1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix the right thing

This commit is contained in:
Matthew Brown 2018-03-20 23:55:26 -04:00
parent 75e76eb327
commit 7a5d4b8516
3 changed files with 22 additions and 7 deletions

View File

@ -333,8 +333,9 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
? $parser_param->default->inferredType
: null;
if ($default_type &&
!TypeChecker::isContainedBy(
if ($default_type
&& !$default_type->isMixed()
&& !TypeChecker::isContainedBy(
$codebase,
$default_type,
$param_type
@ -342,8 +343,9 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
) {
if (IssueBuffer::accepts(
new InvalidParamDefault(
'Default value for argument ' . ($offset + 1) . ' of method ' . $cased_method_id .
' does not match the given type ' . $param_type,
'Default value type ' . $default_type . ' for argument ' . ($offset + 1)
. ' of method ' . $cased_method_id
. ' does not match the given type ' . $param_type,
$function_param->type_location
)
)) {

View File

@ -550,11 +550,11 @@ class PropertyAssignmentChecker
}
if (!$type_match_found && !$type_coerced) {
foreach ($class_property_type->getTypes() as $class_property_type_part) {
foreach ($assignment_value_type->getTypes() as $assignment_value_type_part) {
if (TypeChecker::isContainedBy(
$project_checker->codebase,
$assignment_value_type,
new Type\Union([$class_property_type_part]),
new Type\Union([$assignment_value_type_part]),
$class_property_type,
true,
true
)) {

View File

@ -936,6 +936,19 @@ class PropertyTypeTest extends TestCase
}',
'error_message' => 'InvalidPropertyAssignmentValue',
],
'possiblyBadAssignment' => [
'<?php
class A {
/** @var string */
public $foo;
public function barBar(): void
{
$this->foo = rand(0, 1) ? 5 : "hello";
}
}',
'error_message' => 'PossiblyInvalidPropertyAssignmentValue',
],
'badAssignmentAsWell' => [
'<?php
$a = "hello";