1
0
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:
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
) {
// 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;

View File

@ -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',
]
];
}
}