From 2cbd8b05d15bd7c8f4dde01af43c386fec15b88d Mon Sep 17 00:00:00 2001 From: Ivan Sidorov Date: Wed, 21 Aug 2024 20:34:49 +0000 Subject: [PATCH 1/4] Creating Success Regression Tests --- tests/MixinAnnotationTest.php | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/MixinAnnotationTest.php b/tests/MixinAnnotationTest.php index 88529223bd8..824e582cf2e 100644 --- a/tests/MixinAnnotationTest.php +++ b/tests/MixinAnnotationTest.php @@ -616,6 +616,21 @@ class A {} (new A)->foo;', 'error_message' => 'UndefinedPropertyFetch', ], + 'undefinedMixinClassWithPropertyFetch_WithMagicMethod' => [ + 'code' => 'foo;', + 'error_message' => 'UndefinedMagicPropertyFetch', + ], 'undefinedMixinClassWithPropertyAssignment' => [ 'code' => 'foo();', 'error_message' => 'UndefinedMethod', ], + 'undefinedMixinClassWithMethodCall_WithMagicMethod' => [ + 'code' => 'foo();', + 'error_message' => 'UndefinedMagicMethod', + ], + 'undefinedMixinClassWithStaticMethodCall' => [ + 'code' => ' 'UndefinedMethod', + ], + 'undefinedMixinClassWithStaticMethodCall_WithMagicMethod' => [ + 'code' => ' 'UndefinedMagicMethod', + ], 'inheritTemplatedMixinWithSelf' => [ 'code' => ' Date: Wed, 21 Aug 2024 20:38:59 +0000 Subject: [PATCH 2/4] Creating Fail and Fail-Like Tests Failed only "undefinedMixinClassWithPropertyAssignment_WithMagicMethod". Test with data "undefinedMixinClassWithPropertyAssignment_WithMagicMethod_Similar" is passed. Problem: 1) Psalm\Tests\MixinAnnotationTest::testInvalidCodeWithIssues with data set "undefinedMixinClassWithPropertyAssignment_WithMagicMethod" Failed asserting that issue with "UndefinedMagicPropertyAssignment" was emitted. Other issues reported: - UndefinedDocblockClass - src/somefile.php:6:27 - Docblock-defined class, interface or enum named B does not exist Failed asserting that false is true. 2) Psalm\Tests\MixinAnnotationTest::testInvalidCode with data set "undefinedMixinClassWithPropertyAssignment_WithMagicMethod" Failed asserting that exception message 'UndefinedDocblockClass - src/somefile.php:6:27 - Docblock-defined class, interface or enum named B does not exist' matches '/\bUndefinedMagicPropertyAssignment\b/'. --- tests/MixinAnnotationTest.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/MixinAnnotationTest.php b/tests/MixinAnnotationTest.php index 824e582cf2e..53f9b9dd9b7 100644 --- a/tests/MixinAnnotationTest.php +++ b/tests/MixinAnnotationTest.php @@ -639,6 +639,34 @@ class A {} (new A)->foo = "bar";', 'error_message' => 'UndefinedPropertyAssignment', ], + 'undefinedMixinClassWithPropertyAssignment_WithMagicMethod' => [ + 'code' => 'foo = "bar";', + 'error_message' => 'UndefinedMagicPropertyAssignment', + ], + 'undefinedMixinClassWithPropertyAssignment_WithMagicMethod_Similar' => [ + 'code' => 'foo = "bar";', + 'error_message' => 'UndefinedMagicPropertyAssignment', + ], 'undefinedMixinClassWithMethodCall' => [ 'code' => ' Date: Wed, 21 Aug 2024 20:38:37 +0000 Subject: [PATCH 3/4] Resolve Fail Test Variable `$var_id` added by commit: Title: Fix #302 - add a way to seal objects with magic properties SHA: a08306973a74c8c93b91a0e2a4061dc80b2b358b Date: 2017-11-17 File: src/Psalm/Checker/Statements/Expression/AssignmentChecker.php Line: 682 After removing the `$var_id` variable, all project tests are successful. --- .../Assignment/InstancePropertyAssignmentAnalyzer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/InstancePropertyAssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/InstancePropertyAssignmentAnalyzer.php index bedec945c25..b8c236e087f 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/InstancePropertyAssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/InstancePropertyAssignmentAnalyzer.php @@ -1087,7 +1087,7 @@ private static function analyzeAtomicAssignment( * If we have an explicit list of all allowed magic properties on the class, and we're * not in that list, fall through */ - if (!$var_id || !$class_storage->hasSealedProperties($codebase->config)) { + if (!$class_storage->hasSealedProperties($codebase->config)) { if (!$context->collect_initializations && !$context->collect_mutations) { self::taintProperty( $statements_analyzer, From 0b83d3f756bf17c9b9f8e85ce2c48a06953d8afb Mon Sep 17 00:00:00 2001 From: Ivan Sidorov Date: Wed, 21 Aug 2024 20:39:30 +0000 Subject: [PATCH 4/4] Deleting Fail-Like Test Deleting test with data "undefinedMixinClassWithPropertyAssignment_WithMagicMethod_Similar". It was only needed to make sure that the failed test was designed with the right expectation. --- tests/MixinAnnotationTest.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/tests/MixinAnnotationTest.php b/tests/MixinAnnotationTest.php index 53f9b9dd9b7..3c0c11b26bb 100644 --- a/tests/MixinAnnotationTest.php +++ b/tests/MixinAnnotationTest.php @@ -652,21 +652,6 @@ public function __set(string $name, string $value) {} (new A)->foo = "bar";', 'error_message' => 'UndefinedMagicPropertyAssignment', ], - 'undefinedMixinClassWithPropertyAssignment_WithMagicMethod_Similar' => [ - 'code' => 'foo = "bar";', - 'error_message' => 'UndefinedMagicPropertyAssignment', - ], 'undefinedMixinClassWithMethodCall' => [ 'code' => '