diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/PropertyAssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/PropertyAssignmentAnalyzer.php index ce55b0bbc..b5975b550 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/PropertyAssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/PropertyAssignmentAnalyzer.php @@ -256,12 +256,7 @@ class PropertyAssignmentAnalyzer $property_id = $lhs_type_part->value . '::$' . $prop_name; $property_ids[] = $property_id; - $statements_analyzer_source = $statements_analyzer->getSource(); - if ($codebase->methodExists($lhs_type_part->value . '::__set') - && (!$statements_analyzer_source instanceof FunctionLikeAnalyzer - || $statements_analyzer_source->getMethodId() !== $lhs_type_part->value . '::__set') - && (!$context->self || !$codebase->classExtends($context->self, $lhs_type_part->value)) && (!$codebase->properties->propertyExists($property_id) || ($lhs_var_id !== '$this' && $lhs_type_part->value !== $context->self diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/PropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/PropertyFetchAnalyzer.php index b579d3d95..cb7be7377 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/PropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/PropertyFetchAnalyzer.php @@ -291,12 +291,7 @@ class PropertyFetchAnalyzer ); } - $statements_analyzer_source = $statements_analyzer->getSource(); - if ($codebase->methodExists($lhs_type_part->value . '::__get') - && (!$statements_analyzer_source instanceof FunctionLikeAnalyzer - || $statements_analyzer_source->getMethodId() !== $lhs_type_part->value . '::__get') - && (!$context->self || !$codebase->classExtends($context->self, $lhs_type_part->value)) && (!$codebase->properties->propertyExists($property_id) || ($stmt_var_id !== '$this' && $lhs_type_part->value !== $context->self diff --git a/tests/MagicPropertyTest.php b/tests/MagicPropertyTest.php index 47d703675..a823c14ae 100644 --- a/tests/MagicPropertyTest.php +++ b/tests/MagicPropertyTest.php @@ -323,6 +323,22 @@ class MagicPropertyTest extends TestCase 'assertions' => [], 'error_level' => ['MixedArgument'], ], + 'accessInMagicGet' => [ + 'other; + case "other": + return "foo"; + } + return "default"; + } + }', + 'assertions' => [], + 'error_level' => ['MixedReturnStatement', 'MixedInferredReturnType'], + ], ]; } @@ -612,22 +628,6 @@ class MagicPropertyTest extends TestCase 'error_message' => 'MixedTypeCoercion', 'error_levels' => ['MixedAssignment'], ], - 'misnamedPropertyByVariable' => [ - '$var_name; - } - - return null; - } - }', - 'error_message' => 'UndefinedThisPropertyFetch', - ], ]; } } diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index c77de972d..8e312f0fe 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -1809,6 +1809,22 @@ class PropertyTypeTest extends TestCase }', 'error_message' => 'UndefinedMethod', ], + 'misnamedPropertyByVariable' => [ + '$var_name; + } + + return null; + } + }', + 'error_message' => 'UndefinedThisPropertyFetch', + ], ]; } }