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

Fix some property inference bugs

This commit is contained in:
Brown 2020-07-08 14:43:36 -04:00
parent 619c384509
commit 33a834bb0b
4 changed files with 27 additions and 8 deletions

View File

@ -1655,6 +1655,10 @@ class ClassAnalyzer extends ClassLikeAnalyzer
: $this->inferred_property_types[$property_name];
}
if ($suggested_type && !$property_storage->has_default && $property_storage->is_static) {
$suggested_type->addType(new Type\Atomic\TNull());
}
if ($suggested_type && !$suggested_type->isNull()) {
$message .= ' - consider ' . str_replace(
['<array-key, mixed>', '<empty, empty>'],

View File

@ -778,10 +778,7 @@ class InstancePropertyAssignmentAnalyzer
$source_analyzer->inferred_property_types[$prop_name]
);
} else {
$source_analyzer->inferred_property_types[$prop_name] =
($context->inside_constructor || $context->collect_initializations)
? $assignment_value_type
: Type::combineUnionTypes(Type::getNull(), $assignment_value_type);
$source_analyzer->inferred_property_types[$prop_name] = $assignment_value_type;
}
}
}

View File

@ -201,10 +201,7 @@ class StaticPropertyAssignmentAnalyzer
$source_analyzer->inferred_property_types[$prop_name_name]
);
} else {
$source_analyzer->inferred_property_types[$prop_name_name] = Type::combineUnionTypes(
Type::getNull(),
$assignment_value_type
);
$source_analyzer->inferred_property_types[$prop_name_name] = $assignment_value_type;
}
}
} else {

View File

@ -240,6 +240,27 @@ class MissingPropertyTypeTest extends FileManipulationTest
['MissingPropertyType'],
true,
],
'addMissingTypehintWithDefault' => [
'<?php
class A {
public $u = false;
public function bar() {
$this->u = true;
}
}',
'<?php
class A {
public bool $u = false;
public function bar() {
$this->u = true;
}
}',
'7.4',
['MissingPropertyType'],
true,
],
];
}
}