8
8
function doFoo (string $ s ) {
9
9
if (1 === preg_match ('/(?<major>\d+)\.(?<minor>\d+)(?:\.(?<patch>\d+))?/ ' , $ s , $ matches , PREG_UNMATCHED_AS_NULL )) {
10
10
11
- assertType ('array{0: string, major: numeric-string, 1: numeric-string, minor: numeric-string, 2: numeric-string, patch: numeric-string|null, 3: numeric-string|null} ' , $ matches );
11
+ assertType ('array{0: non-falsy- string, major: numeric-string, 1: numeric-string, minor: numeric-string, 2: numeric-string, patch: numeric-string|null, 3: numeric-string|null} ' , $ matches );
12
12
}
13
13
}
14
14
@@ -23,11 +23,11 @@ function doUnmatchedAsNull(string $s): void {
23
23
function unmatchedAsNullWithOptionalGroup (string $ s ): void {
24
24
if (preg_match ('/Price: (£|€)?\d+/ ' , $ s , $ matches , PREG_UNMATCHED_AS_NULL )) {
25
25
// with PREG_UNMATCHED_AS_NULL the offset 1 will always exist. It is correct that it's nullable because it's optional though
26
- assertType ("array{string, '£'|'€'|null} " , $ matches );
26
+ assertType ("array{non-falsy- string, '£'|'€'|null} " , $ matches );
27
27
} else {
28
28
assertType ('array{} ' , $ matches );
29
29
}
30
- assertType ("array{}|array{string, '£'|'€'|null} " , $ matches );
30
+ assertType ("array{}|array{non-falsy- string, '£'|'€'|null} " , $ matches );
31
31
}
32
32
33
33
function bug11331a (string $ url ):void {
@@ -37,7 +37,7 @@ function bug11331a(string $url):void {
37
37
(?<a>.+)
38
38
)?
39
39
(?<b>.+)}mix ' , $ url , $ matches , PREG_UNMATCHED_AS_NULL )) {
40
- assertType ('array{0: string, a: non-empty-string|null, 1: non-empty-string|null, b: non-empty-string, 2: non-empty-string} ' , $ matches );
40
+ assertType ('array{0: non-empty- string, a: non-empty-string|null, 1: non-empty-string|null, b: non-empty-string, 2: non-empty-string} ' , $ matches );
41
41
}
42
42
}
43
43
@@ -63,20 +63,20 @@ function bug11331c(string $url):void {
63
63
([^/]+?)
64
64
(?:\.git|/)?
65
65
$}x ' , $ url , $ matches , PREG_UNMATCHED_AS_NULL )) {
66
- assertType ('array{string, non-empty-string|null, non-empty-string|null, non-empty-string, non-empty-string} ' , $ matches );
66
+ assertType ('array{non-falsy- string, non-empty-string|null, non-empty-string|null, non-empty-string, non-empty-string} ' , $ matches );
67
67
}
68
68
}
69
69
70
70
class UnmatchedAsNullWithTopLevelAlternation {
71
71
function doFoo (string $ s ): void {
72
72
if (preg_match ('/Price: (?:(£)|(€))\d+/ ' , $ s , $ matches , PREG_UNMATCHED_AS_NULL )) {
73
- assertType ("array{string, '£'|null, '€'|null} " , $ matches ); // could be tagged union
73
+ assertType ("array{non-falsy- string, '£'|null, '€'|null} " , $ matches ); // could be tagged union
74
74
}
75
75
}
76
76
77
77
function doBar (string $ s ): void {
78
78
if (preg_match ('/Price: (?:(£)|(€))?\d+/ ' , $ s , $ matches , PREG_UNMATCHED_AS_NULL )) {
79
- assertType ("array{string, '£'|null, '€'|null} " , $ matches ); // could be tagged union
79
+ assertType ("array{non-falsy- string, '£'|null, '€'|null} " , $ matches ); // could be tagged union
80
80
}
81
81
}
82
82
}
@@ -85,101 +85,101 @@ function (string $size): void {
85
85
if (preg_match ('/ab(\d){2,4}xx([0-9])?e?/ ' , $ size , $ matches , PREG_UNMATCHED_AS_NULL ) !== 1 ) {
86
86
throw new InvalidArgumentException (sprintf ('Invalid size "%s" ' , $ size ));
87
87
}
88
- assertType ('array{string, numeric-string, numeric-string|null} ' , $ matches );
88
+ assertType ('array{non-falsy- string, numeric-string, numeric-string|null} ' , $ matches );
89
89
};
90
90
91
91
function (string $ size ): void {
92
92
if (preg_match ('/a(\dAB){2}b(\d){2,4}([1-5])([1-5a-z])e?/ ' , $ size , $ matches , PREG_UNMATCHED_AS_NULL ) !== 1 ) {
93
93
throw new InvalidArgumentException (sprintf ('Invalid size "%s" ' , $ size ));
94
94
}
95
- assertType ('array{string, non-falsy-string, numeric-string, numeric-string, non-empty-string} ' , $ matches );
95
+ assertType ('array{non-falsy- string, non-falsy-string, numeric-string, numeric-string, non-empty-string} ' , $ matches );
96
96
};
97
97
98
98
function (string $ size ): void {
99
99
if (preg_match ('/ab(ab(\d)){2,4}xx([0-9][a-c])?e?/ ' , $ size , $ matches , PREG_UNMATCHED_AS_NULL ) !== 1 ) {
100
100
throw new InvalidArgumentException (sprintf ('Invalid size "%s" ' , $ size ));
101
101
}
102
- assertType ('array{string, non-falsy-string, numeric-string, non-falsy-string|null} ' , $ matches );
102
+ assertType ('array{non-falsy- string, non-falsy-string, numeric-string, non-falsy-string|null} ' , $ matches );
103
103
};
104
104
105
105
function (string $ size ): void {
106
106
if (preg_match ('/ab(\d+)e(\d?)/ ' , $ size , $ matches , PREG_UNMATCHED_AS_NULL ) !== 1 ) {
107
107
throw new InvalidArgumentException (sprintf ('Invalid size "%s" ' , $ size ));
108
108
}
109
- assertType ("array{string, numeric-string, ''|numeric-string} " , $ matches );
109
+ assertType ("array{non-falsy- string, numeric-string, ''|numeric-string} " , $ matches );
110
110
};
111
111
112
112
function (string $ size ): void {
113
113
if (preg_match ('/ab(?P<num>\d+)e?/ ' , $ size , $ matches , PREG_UNMATCHED_AS_NULL ) !== 1 ) {
114
114
throw new InvalidArgumentException (sprintf ('Invalid size "%s" ' , $ size ));
115
115
}
116
- assertType ('array{0: string, num: numeric-string, 1: numeric-string} ' , $ matches );
116
+ assertType ('array{0: non-falsy- string, num: numeric-string, 1: numeric-string} ' , $ matches );
117
117
};
118
118
119
119
function (string $ size ): void {
120
120
if (preg_match ('/ab(\d\d)/ ' , $ size , $ matches , PREG_UNMATCHED_AS_NULL ) !== 1 ) {
121
121
throw new InvalidArgumentException (sprintf ('Invalid size "%s" ' , $ size ));
122
122
}
123
- assertType ('array{string, non-falsy-string&numeric-string} ' , $ matches );
123
+ assertType ('array{non-falsy- string, non-falsy-string&numeric-string} ' , $ matches );
124
124
};
125
125
126
126
function (string $ size ): void {
127
127
if (preg_match ('/ab(\d+\s)e?/ ' , $ size , $ matches , PREG_UNMATCHED_AS_NULL ) !== 1 ) {
128
128
throw new InvalidArgumentException (sprintf ('Invalid size "%s" ' , $ size ));
129
129
}
130
- assertType ('array{string, non-falsy-string} ' , $ matches );
130
+ assertType ('array{non-falsy- string, non-falsy-string} ' , $ matches );
131
131
};
132
132
133
133
function (string $ size ): void {
134
134
if (preg_match ('/ab(\s)e?/ ' , $ size , $ matches , PREG_UNMATCHED_AS_NULL ) !== 1 ) {
135
135
throw new InvalidArgumentException (sprintf ('Invalid size "%s" ' , $ size ));
136
136
}
137
- assertType ('array{string, non-empty-string} ' , $ matches );
137
+ assertType ('array{non-falsy- string, non-empty-string} ' , $ matches );
138
138
};
139
139
140
140
function (string $ size ): void {
141
141
if (preg_match ('/ab(\S)e?/ ' , $ size , $ matches , PREG_UNMATCHED_AS_NULL ) !== 1 ) {
142
142
throw new InvalidArgumentException (sprintf ('Invalid size "%s" ' , $ size ));
143
143
}
144
- assertType ('array{string, non-empty-string} ' , $ matches );
144
+ assertType ('array{non-falsy- string, non-empty-string} ' , $ matches );
145
145
};
146
146
147
147
function (string $ size ): void {
148
148
if (preg_match ('/ab(\S?)e?/ ' , $ size , $ matches , PREG_UNMATCHED_AS_NULL ) !== 1 ) {
149
149
throw new InvalidArgumentException (sprintf ('Invalid size "%s" ' , $ size ));
150
150
}
151
- assertType ('array{string, string} ' , $ matches );
151
+ assertType ('array{non-falsy- string, string} ' , $ matches );
152
152
};
153
153
154
154
function (string $ size ): void {
155
155
if (preg_match ('/ab(\S)?e?/ ' , $ size , $ matches , PREG_UNMATCHED_AS_NULL ) !== 1 ) {
156
156
throw new InvalidArgumentException (sprintf ('Invalid size "%s" ' , $ size ));
157
157
}
158
- assertType ('array{string, non-empty-string|null} ' , $ matches );
158
+ assertType ('array{non-falsy- string, non-empty-string|null} ' , $ matches );
159
159
};
160
160
161
161
function (string $ size ): void {
162
162
if (preg_match ('/ab(\d+\d?)e?/ ' , $ size , $ matches , PREG_UNMATCHED_AS_NULL ) !== 1 ) {
163
163
throw new InvalidArgumentException (sprintf ('Invalid size "%s" ' , $ size ));
164
164
}
165
- assertType ('array{string, numeric-string} ' , $ matches );
165
+ assertType ('array{non-falsy- string, numeric-string} ' , $ matches );
166
166
};
167
167
168
168
function (string $ s ): void {
169
169
if (preg_match ('/Price: ([2-5])/i ' , $ s , $ matches , PREG_UNMATCHED_AS_NULL )) {
170
- assertType ('array{string, numeric-string} ' , $ matches );
170
+ assertType ('array{non-falsy- string, numeric-string} ' , $ matches );
171
171
}
172
172
};
173
173
174
174
function (string $ s ): void {
175
175
if (preg_match ('/Price: ([2-5A-Z])/i ' , $ s , $ matches , PREG_UNMATCHED_AS_NULL )) {
176
- assertType ('array{string, non-empty-string} ' , $ matches );
176
+ assertType ('array{non-falsy- string, non-empty-string} ' , $ matches );
177
177
}
178
178
};
179
179
180
180
function (string $ s ): void {
181
181
if (preg_match ('/^%([0-9]*\$)?[0-9]*\.?[0-9]*([sbdeEfFgGhHouxX])$/ ' , $ s , $ matches , PREG_UNMATCHED_AS_NULL ) === 1 ) {
182
- assertType ("array{string, non-falsy-string|null, 'b'|'d'|'E'|'e'|'F'|'f'|'G'|'g'|'H'|'h'|'o'|'s'|'u'|'X'|'x'} " , $ matches );
182
+ assertType ("array{non-falsy- string, non-falsy-string|null, 'b'|'d'|'E'|'e'|'F'|'f'|'G'|'g'|'H'|'h'|'o'|'s'|'u'|'X'|'x'} " , $ matches );
183
183
}
184
184
};
185
185
@@ -201,22 +201,22 @@ function (string $s): void {
201
201
202
202
function (string $ s ): void {
203
203
if (preg_match ('~a|(\d)|(\s)~ ' , $ s , $ matches , PREG_UNMATCHED_AS_NULL )) {
204
- assertType ("array{string, numeric-string|null, non-empty-string|null} " , $ matches );
204
+ assertType ("array{non-empty- string, numeric-string|null, non-empty-string|null} " , $ matches );
205
205
} else {
206
206
assertType ("array{} " , $ matches );
207
207
}
208
- assertType ("array{}|array{string, numeric-string|null, non-empty-string|null} " , $ matches );
208
+ assertType ("array{}|array{non-empty- string, numeric-string|null, non-empty-string|null} " , $ matches );
209
209
};
210
210
211
211
function (string $ s ): void {
212
212
if (preg_match ('~a|(\d)|(\s)~ ' , $ s , $ matches , PREG_UNMATCHED_AS_NULL |PREG_OFFSET_CAPTURE ) === 1 ) {
213
- assertType ("array{array{string|null, int<-1, max>}, array{numeric-string|null, int<-1, max>}, array{non-empty-string|null, int<-1, max>}} " , $ matches );
213
+ assertType ("array{array{non-empty- string|null, int<-1, max>}, array{numeric-string|null, int<-1, max>}, array{non-empty-string|null, int<-1, max>}} " , $ matches );
214
214
}
215
215
};
216
216
217
217
function (string $ s ): void {
218
218
if (preg_match ('~a|((u)x)|((v)y)~ ' , $ s , $ matches , PREG_UNMATCHED_AS_NULL ) === 1 ) {
219
- assertType ("array{string, 'ux'|null, 'u'|null, 'vy'|null, 'v'|null} " , $ matches );
219
+ assertType ("array{non-empty- string, 'ux'|null, 'u'|null, 'vy'|null, 'v'|null} " , $ matches );
220
220
}
221
221
};
222
222
0 commit comments