1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #168 and add test case

This commit is contained in:
Matthew Brown 2017-06-11 19:20:07 -04:00
parent 90d0d12f6c
commit 72e1221a2f
2 changed files with 19 additions and 5 deletions

View File

@ -750,7 +750,7 @@ class TypeChecker
$input_type_part instanceof TNamedObject $input_type_part instanceof TNamedObject
) { ) {
// check whether the object has a __toString method // check whether the object has a __toString method
if (ClassChecker::classExists($input_type_part->value, $file_checker) && if (ClassChecker::classOrInterfaceExists($input_type_part->value, $file_checker) &&
MethodChecker::methodExists($input_type_part->value . '::__toString', $file_checker) MethodChecker::methodExists($input_type_part->value . '::__toString', $file_checker)
) { ) {
$to_string_cast = true; $to_string_cast = true;

View File

@ -96,6 +96,20 @@ class ToStringTest extends TestCase
fooFoo(new A());', fooFoo(new A());',
'error_message' => 'ImplicitToStringCast', 'error_message' => 'ImplicitToStringCast',
], ],
'implicitCastFromInterface' => [
'<?php
interface I {
public function __toString();
}
function takesString(string $str) : void { }
function takesI(I $i) : void
{
takesString($i);
}',
'error_message' => 'ImplicitToStringCast',
]
]; ];
} }
} }