mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
parent
8ab5a0f504
commit
ce8fb459e9
@ -391,7 +391,10 @@ class ParseTree
|
||||
case '?':
|
||||
if ($next_token === null || $next_token[0] !== ':') {
|
||||
while (($current_leaf instanceof ParseTree\Value
|
||||
|| $current_leaf instanceof ParseTree\UnionTree)
|
||||
|| $current_leaf instanceof ParseTree\UnionTree
|
||||
|| $current_leaf instanceof ParseTree\ObjectLikeTree
|
||||
|| $current_leaf instanceof ParseTree\GenericTree
|
||||
|| $current_leaf instanceof ParseTree\IntersectionTree)
|
||||
&& $current_leaf->parent
|
||||
) {
|
||||
$current_leaf = $current_leaf->parent;
|
||||
|
@ -659,6 +659,39 @@ class TypeParseTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testConditionalTypeWithObjectLikeArray()
|
||||
{
|
||||
$this->assertSame(
|
||||
'(T is array{a: string} ? string : int)',
|
||||
(string) Type::parseString('(T is array{a: string} ? string : int)', null, ['T' => ['' => [Type::getArray()]]])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testConditionalTypeWithGeneric()
|
||||
{
|
||||
$this->assertSame(
|
||||
'(T is array<array-key, string> ? string : int)',
|
||||
(string) Type::parseString('(T is array<string> ? string : int)', null, ['T' => ['' => [Type::getArray()]]])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testConditionalTypeWithIntersection()
|
||||
{
|
||||
$this->assertSame(
|
||||
'(T is A&B ? string : int)',
|
||||
(string) Type::parseString('(T is A&B ? string : int)', null, ['T' => ['' => [Type::getArray()]]])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user