mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix #144 - prevent innaccurate __toString warning
This commit is contained in:
parent
f7daa6e768
commit
dc26d2df04
@ -692,6 +692,7 @@ class TypeChecker
|
||||
}
|
||||
|
||||
if ($all_types_contain) {
|
||||
$to_string_cast = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -157,4 +157,32 @@ class ToStringTest extends PHPUnit_Framework_TestCase
|
||||
$context = new Context();
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGoodCast()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
class A {
|
||||
public function __toString() : string
|
||||
{
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
|
||||
/** @param string|A $b */
|
||||
function fooFoo($b) : void {}
|
||||
|
||||
/** @param A|string $b */
|
||||
function barBar($b) : void {}
|
||||
|
||||
fooFoo(new A());
|
||||
barBar(new A());
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$context = new Context();
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user