1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #2224 - make sure literal strings are put into appropriate arrays when templating

This commit is contained in:
Matthew Brown 2019-10-10 23:38:57 -04:00
parent c419e0e798
commit 0556f28a9f
2 changed files with 51 additions and 0 deletions

View File

@ -1593,6 +1593,16 @@ class Union
unset($this->types[$key]);
}
foreach ($new_types as $type) {
if ($type instanceof TLiteralString) {
$this->literal_string_types[$type->getKey()] = $type;
} elseif ($type instanceof TLiteralInt) {
$this->literal_int_types[$type->getKey()] = $type;
} elseif ($type instanceof TLiteralFloat) {
$this->literal_float_types[$type->getKey()] = $type;
}
}
$this->types = array_merge($this->types, $new_types);
}

View File

@ -1764,6 +1764,47 @@ class ClassTemplateTest extends TestCase
return $bar->get();
}'
],
'templatedThing' => [
'<?php
/**
* @template T
*/
final class Value {
/**
* @psalm-var T
*/
private $value;
/**
* @psalm-param T $value
*/
public function __construct($value) {
$this->value = $value;
}
/**
* @psalm-return T
*/
public function value() {
return $this->value;
}
}
/**
* @template T
* @psalm-param T $value
* @psalm-return Value<T>
*/
function value($value): Value {
return new Value($value);
}
/**
* @psalm-param Value<string> $value
*/
function client($value): void {}
client(value("awdawd"));'
],
];
}