diff --git a/src/Psalm/Checker/TypeChecker.php b/src/Psalm/Checker/TypeChecker.php index 33b20f480..538914895 100644 --- a/src/Psalm/Checker/TypeChecker.php +++ b/src/Psalm/Checker/TypeChecker.php @@ -638,6 +638,7 @@ class TypeChecker if ($input_type_part instanceof TClassString) { $type_coerced = true; + $type_coerced_from_scalar = true; return false; } diff --git a/tests/ConstantTest.php b/tests/ConstantTest.php index ba35a5131..6544a9e40 100644 --- a/tests/ConstantTest.php +++ b/tests/ConstantTest.php @@ -221,6 +221,23 @@ class ConstantTest extends TestCase fwrite(STDOUT, "asd"); fwrite(STDERR, "zcx");' ], + 'classStringArrayOffset' => [ + ' 1, + B::class => 2, + ]; + + /** + * @param class-string $s + */ + function foo(string $s) : void { + if (isset(C[$s])) {} + }', + ], ]; }