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:
parent
90d0d12f6c
commit
72e1221a2f
@ -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;
|
||||||
|
@ -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',
|
||||||
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user