Skip to content

Commit 7fab7a5

Browse files
staabmondrejmirtes
authored andcommitted
Test pattern of union type
1 parent e8bb95c commit 7fab7a5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/PHPStan/Analyser/nsrt/preg_match_shapes_php74.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,16 @@ function testPregMatchEqualToOneFalseyContextInverted(string $value): void {
219219
assertType('array{string, string}', $matches);
220220
}
221221
}
222+
223+
function testUnionPattern(string $s): void
224+
{
225+
if (rand(0,1)) {
226+
$pattern = '/Price: (\d+)/i';
227+
} else {
228+
$pattern = '/Price: (\d+)(\d+)(\d+)/';
229+
}
230+
if (preg_match($pattern, $s, $matches)) {
231+
assertType('array{string, string, string, string}|array{string, string}', $matches);
232+
}
233+
assertType('array{}|array{string, string, string, string}|array{string, string}', $matches);
234+
}

0 commit comments

Comments
 (0)