mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix lowercase-string to constant string coercion
This commit is contained in:
parent
6a4e7931e6
commit
8dd49b1cbf
@ -1276,6 +1276,18 @@ class TypeAnalyzer
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($input_type_part instanceof Type\Atomic\TLowercaseString
|
||||
&& $container_type_part instanceof TLiteralString
|
||||
&& strtolower($container_type_part->value) === $container_type_part->value
|
||||
) {
|
||||
if ($atomic_comparison_result) {
|
||||
$atomic_comparison_result->type_coerced = true;
|
||||
$atomic_comparison_result->type_coerced_from_scalar = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (($container_type_part instanceof TClassString || $container_type_part instanceof TLiteralClassString)
|
||||
&& ($input_type_part instanceof TClassString || $input_type_part instanceof TLiteralClassString)
|
||||
) {
|
||||
|
@ -703,6 +703,24 @@ class ConstantTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'lowercaseStringAccessClassConstant' => [
|
||||
'<?php
|
||||
class A {
|
||||
const C = [
|
||||
"a" => 1,
|
||||
"b" => 2,
|
||||
"c" => 3
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lowercase-string $s
|
||||
*/
|
||||
function foo(string $s, string $t) : void {
|
||||
echo A::C[$t];
|
||||
echo A::C[$s];
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user