1
0
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:
Matt Brown 2017-04-21 14:23:09 -04:00
parent f7daa6e768
commit dc26d2df04
2 changed files with 29 additions and 0 deletions

View File

@ -692,6 +692,7 @@ class TypeChecker
}
if ($all_types_contain) {
$to_string_cast = false;
return true;
}

View File

@ -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);
}
}