Skip to content

Commit

Permalink
Merge pull request #10615 from weirdan/10589-fix-missing-MissingConst…
Browse files Browse the repository at this point in the history
…ructor-with-native-mixed-property
  • Loading branch information
weirdan authored Jan 30, 2024
2 parents e02276a + ca9a12d commit baa8660
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1127,8 +1127,11 @@ private function checkPropertyInitialization(
$uninitialized_variables[] = '$this->' . $property_name;
$uninitialized_properties[$property_class_name . '::$' . $property_name] = $property;

if ($property->type && !$property->type->isMixed()) {
$uninitialized_typed_properties[$property_class_name . '::$' . $property_name] = $property;
if ($property->type) {
// Complain about all natively typed properties and all non-mixed docblock typed properties
if (!$property->type->from_docblock || !$property->type->isMixed()) {
$uninitialized_typed_properties[$property_class_name . '::$' . $property_name] = $property;
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/PropertyTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3827,6 +3827,15 @@ class A {
',
'error_message' => 'UndefinedPropertyAssignment',
],
'nativeMixedPropertyWithNoConstructor' => [
'code' => <<< 'PHP'
<?php
class A {
public mixed $foo;
}
PHP,
'error_message' => 'MissingConstructor',
],
];
}
}

0 comments on commit baa8660

Please sign in to comment.