@@ -44,9 +44,9 @@ function doMatch(string $s): void {
44
44
assertType ('array{}|array{0: string, 1: non-empty-string, 2: string, 3: non-empty-string, 4?: non-empty-string} ' , $ matches );
45
45
46
46
if (preg_match ('/(a)(?<name>b)*(c)(d)*/ ' , $ s , $ matches )) {
47
- assertType (' array{0: string, 1: non-empty-string , name: string, 2: string, 3: non-empty-string , 4?: non-empty-string} ' , $ matches );
47
+ assertType (" array{0: string, 1: 'a' , name: string, 2: string, 3: 'c' , 4?: 'd'} " , $ matches );
48
48
}
49
- assertType (' array{}|array{0: string, 1: non-empty-string , name: string, 2: string, 3: non-empty-string , 4?: non-empty-string} ' , $ matches );
49
+ assertType (" array{}|array{0: string, 1: 'a' , name: string, 2: string, 3: 'c' , 4?: 'd'} " , $ matches );
50
50
51
51
if (preg_match ('/(a)(b)*(c)(?<name>d)*/ ' , $ s , $ matches )) {
52
52
assertType ('array{0: string, 1: non-empty-string, 2: string, 3: non-empty-string, name?: non-empty-string, 4?: non-empty-string} ' , $ matches );
@@ -233,13 +233,13 @@ function testUnionPattern(string $s): void
233
233
function doFoo (string $ row ): void
234
234
{
235
235
if (preg_match ('~^(a(b))$~ ' , $ row , $ matches ) === 1 ) {
236
- assertType (' array{string, non-empty-string, non-empty-string} ' , $ matches );
236
+ assertType (" array{string, non-empty-string, 'b'} " , $ matches );
237
237
}
238
238
if (preg_match ('~^(a(b)?)$~ ' , $ row , $ matches ) === 1 ) {
239
239
assertType ('array{0: string, 1: non-empty-string, 2?: non-empty-string} ' , $ matches );
240
240
}
241
241
if (preg_match ('~^(a(b)?)?$~ ' , $ row , $ matches ) === 1 ) {
242
- assertType (' array{0: string, 1?: non-empty-string, 2?: non-empty-string} ' , $ matches );
242
+ assertType (" array{0: string, 1?: non-empty-string, 2?: 'b'} " , $ matches );
243
243
}
244
244
}
245
245
@@ -390,11 +390,11 @@ function unmatchedAsNullWithMandatoryGroup(string $s): void {
390
390
391
391
function (string $ s ): void {
392
392
if (preg_match ('{ ' . preg_quote ('xxx ' ) . '(z)} ' , $ s , $ matches )) {
393
- assertType (' array{string, non-empty-string} ' , $ matches );
393
+ assertType (" array{string, 'z'} " , $ matches );
394
394
} else {
395
395
assertType ('array{} ' , $ matches );
396
396
}
397
- assertType (' array{}|array{string, non-empty-string} ' , $ matches );
397
+ assertType (" array{}|array{string, 'z'} " , $ matches );
398
398
};
399
399
400
400
function (string $ s ): void {
@@ -417,11 +417,11 @@ function (string $s): void {
417
417
418
418
function (string $ s ): void {
419
419
if (preg_match ('{ ' . preg_quote ($ s ) . '(z) ' . preg_quote ($ s ) . '(?:abc)(def)?} ' , $ s , $ matches )) {
420
- assertType (' array{0: string, 1: non-empty-string , 2?: non-empty-string} ' , $ matches );
420
+ assertType (" array{0: string, 1: 'z' , 2?: non-empty-string " , $ matches );
421
421
} else {
422
422
assertType ('array{} ' , $ matches );
423
423
}
424
- assertType (' array{}|array{0: string, 1: non-empty-string , 2?: non-empty-string} ' , $ matches );
424
+ assertType (" array{}|array{0: string, 1: 'z' , 2?: non-empty-string} " , $ matches );
425
425
};
426
426
427
427
function (string $ s , $ mixed ): void {
@@ -546,3 +546,15 @@ public function test2(string $str): void
546
546
}
547
547
}
548
548
}
549
+
550
+ function (string $ s ): void {
551
+ if (rand (0 ,1 )) {
552
+ $ p = '/Price: (£)(abc)/i ' ;
553
+ } else {
554
+ $ p = '/Price: (\d)(b)/i ' ;
555
+ }
556
+
557
+ if (preg_match ($ p , $ s , $ matches )) {
558
+ assertType ("array{string, '£', 'abc'}|array{string, numeric-string, 'b'} " , $ matches );
559
+ }
560
+ };
0 commit comments