From de8660d348578bcea04d84379ecfa9e043f2c13c Mon Sep 17 00:00:00 2001 From: Yohta Kimura <38206553+rajyan@users.noreply.github.com> Date: Sun, 5 May 2024 15:51:37 +0900 Subject: [PATCH] feat: change isOffsetAccessLegal to maybe --- src/Type/StrictMixedType.php | 2 +- .../Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Type/StrictMixedType.php b/src/Type/StrictMixedType.php index 911a878e99..1871d0e53c 100644 --- a/src/Type/StrictMixedType.php +++ b/src/Type/StrictMixedType.php @@ -332,7 +332,7 @@ public function isOffsetAccessLegal(): TrinaryLogic return TrinaryLogic::createYes(); } } - return TrinaryLogic::createNo(); + return TrinaryLogic::createMaybe(); } public function hasOffsetValueType(Type $offsetType): TrinaryLogic diff --git a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php index 65a6886bab..34292cf6e2 100644 --- a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php @@ -551,6 +551,7 @@ public function testBug7229(): void [ 'Cannot access offset string on mixed.', 24, + 'To offset access on this value, narrow down the type by filtering classes not implementing ArrayAccess::class.', ], ]); } @@ -732,6 +733,7 @@ public function testBug9991(): void [ 'Cannot access offset \'title\' on mixed.', 9, + 'To offset access on this value, narrow down the type by filtering classes not implementing ArrayAccess::class.', ], ]); } @@ -775,6 +777,7 @@ public function testMixed(): void [ 'Cannot access offset 5 on T of mixed.', 12, + 'To offset access on this value, narrow down the type by filtering classes not implementing ArrayAccess::class.', ], [ 'Cannot access offset 5 on T of mixed.', @@ -787,6 +790,7 @@ public function testMixed(): void [ 'Cannot access offset 5 on mixed.', 25, + 'To offset access on this value, narrow down the type by filtering classes not implementing ArrayAccess::class.', ], [ 'Cannot access offset 5 on mixed.', @@ -799,6 +803,7 @@ public function testMixed(): void [ 'Cannot access offset 5 on mixed.', 38, + 'To offset access on this value, narrow down the type by filtering classes not implementing ArrayAccess::class.', ], [ 'Cannot access offset 5 on mixed.',