mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +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
|
||||
) {
|
||||
// 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)
|
||||
) {
|
||||
$to_string_cast = true;
|
||||
|
@ -41,13 +41,13 @@ class ToStringTest extends TestCase
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** @param string|A $b */
|
||||
function fooFoo($b) : void {}
|
||||
|
||||
|
||||
/** @param A|string $b */
|
||||
function barBar($b) : void {}
|
||||
|
||||
|
||||
fooFoo(new A());
|
||||
barBar(new A());',
|
||||
],
|
||||
@ -91,11 +91,25 @@ class ToStringTest extends TestCase
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function fooFoo(string $b) : void {}
|
||||
fooFoo(new A());',
|
||||
'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