1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #993 - create class string from reconciled assertions where necessary

This commit is contained in:
Matthew Brown 2018-09-10 21:55:22 -04:00
parent 661087d445
commit 1b7f215406
2 changed files with 22 additions and 0 deletions

View File

@ -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)]);
}

View File

@ -260,6 +260,24 @@ class ClassStringTest extends TestCase
if ($class === A::class) {}
}',
],
'switchMixedVar' => [
'<?php
class A {}
class B {}
class C {}
/** @param mixed $a */
function foo($a) : void {
switch ($a) {
case A::class:
return;
case B::class:
case C::class:
return;
}
}',
],
];
}