mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Support literal ints in encapsed strings
This commit is contained in:
parent
3140654a44
commit
c3fdfc5795
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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";
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user