diff --git a/src/Psalm/Type/Reconciler.php b/src/Psalm/Type/Reconciler.php index 879703bc9..943bb4ea0 100644 --- a/src/Psalm/Type/Reconciler.php +++ b/src/Psalm/Type/Reconciler.php @@ -1450,6 +1450,10 @@ class Reconciler } } elseif ($scalar_type === 'string' || $scalar_type === 'class-string') { if ($existing_var_type->isMixed()) { + if ($scalar_type === 'class-string') { + return new Type\Union([new Type\Atomic\TLiteralClassString($value)]); + } + return new Type\Union([new Type\Atomic\TLiteralString($value)]); } diff --git a/tests/ClassStringTest.php b/tests/ClassStringTest.php index 8a9267bf4..251e8a1bd 100644 --- a/tests/ClassStringTest.php +++ b/tests/ClassStringTest.php @@ -260,6 +260,24 @@ class ClassStringTest extends TestCase if ($class === A::class) {} }', ], + 'switchMixedVar' => [ + '