diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index b4ebdfdf5ad..53bf67c366a 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -1054,6 +1054,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/array-offset-unset.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8008.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5552.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/native-expressions.php'); } /** diff --git a/tests/PHPStan/Analyser/data/native-expressions.php b/tests/PHPStan/Analyser/data/native-expressions.php new file mode 100644 index 00000000000..a4e7b0a369e --- /dev/null +++ b/tests/PHPStan/Analyser/data/native-expressions.php @@ -0,0 +1,43 @@ +|non-empty-string', $a); + assertNativeType('int|string', $a); + if (is_string($a)) { + assertType('non-empty-string', $a); + assertNativeType('string', $a); + } +} + +class Foo{ + public function __construct( + /** @var non-empty-array */ + private array $array + ){ + assertType('non-empty-array', $this->array); + assertNativeType('array', $this->array); + if(count($array) === 0){ + throw new \InvalidArgumentException(); + } + } +} +