1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Add better handling of expression termination

This commit is contained in:
Brown 2020-04-30 22:23:37 -04:00
parent 9e6797d297
commit 470bf807b7
6 changed files with 38 additions and 3 deletions

View File

@ -165,6 +165,12 @@ class ParseTree
&& !$current_leaf instanceof ParseTree\CallableTree
&& !$current_leaf instanceof ParseTree\MethodTree);
if ($current_leaf instanceof ParseTree\EncapsulationTree
|| $current_leaf instanceof ParseTree\CallableTree
) {
$current_leaf->terminated = true;
}
break;
case '>':
@ -176,6 +182,8 @@ class ParseTree
$current_leaf = $current_leaf->parent;
} while (!$current_leaf instanceof ParseTree\GenericTree);
$current_leaf->terminated = true;
break;
case '}':
@ -187,6 +195,8 @@ class ParseTree
$current_leaf = $current_leaf->parent;
} while (!$current_leaf instanceof ParseTree\ObjectLikeTree);
$current_leaf->terminated = true;
break;
case ',':
@ -392,8 +402,14 @@ class ParseTree
if ($next_token === null || $next_token[0] !== ':') {
while (($current_leaf instanceof ParseTree\Value
|| $current_leaf instanceof ParseTree\UnionTree
|| $current_leaf instanceof ParseTree\ObjectLikeTree
|| $current_leaf instanceof ParseTree\GenericTree
|| ($current_leaf instanceof ParseTree\ObjectLikeTree
&& $current_leaf->terminated)
|| ($current_leaf instanceof ParseTree\GenericTree
&& $current_leaf->terminated)
|| ($current_leaf instanceof ParseTree\EncapsulationTree
&& $current_leaf->terminated)
|| ($current_leaf instanceof ParseTree\CallableTree
&& $current_leaf->terminated)
|| $current_leaf instanceof ParseTree\IntersectionTree)
&& $current_leaf->parent
) {

View File

@ -11,6 +11,11 @@ class CallableTree extends \Psalm\Internal\Type\ParseTree
*/
public $value;
/**
* @var bool
*/
public $terminated = false;
/**
* @param string $value
* @param \Psalm\Internal\Type\ParseTree|null $parent

View File

@ -6,4 +6,8 @@ namespace Psalm\Internal\Type\ParseTree;
*/
class EncapsulationTree extends \Psalm\Internal\Type\ParseTree
{
/**
* @var bool
*/
public $terminated = false;
}

View File

@ -11,6 +11,11 @@ class GenericTree extends \Psalm\Internal\Type\ParseTree
*/
public $value;
/**
* @var bool
*/
public $terminated = false;
/**
* @param string $value
* @param \Psalm\Internal\Type\ParseTree|null $parent

View File

@ -11,6 +11,11 @@ class ObjectLikeTree extends \Psalm\Internal\Type\ParseTree
*/
public $value;
/**
* @var bool
*/
public $terminated = false;
/**
* @param string $value
* @param \Psalm\Internal\Type\ParseTree|null $parent

View File

@ -673,7 +673,7 @@ class TypeParseTest extends TestCase
/**
* @return void
*/
public function testConditionalTypeWithGeneric()
public function testConditionalTypeWithGenericIs()
{
$this->assertSame(
'(T is array<array-key, string> ? string : int)',