1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Support literal ints in encapsed strings

This commit is contained in:
Matt Brown 2021-06-14 16:30:45 -04:00
parent 3140654a44
commit c3fdfc5795
2 changed files with 27 additions and 1 deletions

View File

@ -370,7 +370,12 @@ class CastAnalyzer
|| $atomic_type instanceof TInt
|| $atomic_type instanceof Type\Atomic\TNumeric
) {
$castable_types[] = new Type\Atomic\TNumericString();
if ($atomic_type instanceof Type\Atomic\TLiteralInt) {
$castable_types[] = new Type\Atomic\TLiteralString((string) $atomic_type->value);
} else {
$castable_types[] = new Type\Atomic\TNumericString();
}
continue;
}

View File

@ -566,6 +566,16 @@ class BinaryOperationTest extends TestCase
return $s1 . $s2;
}',
],
'literalConcatCreatesLiteral2' => [
'<?php
/**
* @param literal-string $s1
* @return literal-string
*/
function foo(string $s1): string {
return $s1 . 2;
}',
],
'encapsedStringIncludingLiterals' => [
'<?php
/**
@ -577,6 +587,17 @@ class BinaryOperationTest extends TestCase
return "Hello $s1 $s2";
}',
],
'encapsedStringIncludingLiterals2' => [
'<?php
/**
* @param literal-string $s1
* @return literal-string
*/
function foo(string $s1): string {
$s2 = 2;
return "Hello $s1 $s2";
}',
],
];
}