Skip to content

Commit baa8660

Browse files
authored
Merge pull request #10615 from weirdan/10589-fix-missing-MissingConstructor-with-native-mixed-property
2 parents e02276a + ca9a12d commit baa8660

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Psalm/Internal/Analyzer/ClassAnalyzer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,8 +1127,11 @@ private function checkPropertyInitialization(
11271127
$uninitialized_variables[] = '$this->' . $property_name;
11281128
$uninitialized_properties[$property_class_name . '::$' . $property_name] = $property;
11291129

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

tests/PropertyTypeTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,6 +3827,15 @@ class A {
38273827
',
38283828
'error_message' => 'UndefinedPropertyAssignment',
38293829
],
3830+
'nativeMixedPropertyWithNoConstructor' => [
3831+
'code' => <<< 'PHP'
3832+
<?php
3833+
class A {
3834+
public mixed $foo;
3835+
}
3836+
PHP,
3837+
'error_message' => 'MissingConstructor',
3838+
],
38303839
];
38313840
}
38323841
}

0 commit comments

Comments
 (0)