Skip to content

Commit 1d458e7

Browse files
committed
fix
1 parent 73d2dff commit 1d458e7

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

tests/PHPStan/Analyser/nsrt/bug-11311.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
function doFoo(string $s) {
99
if (1 === preg_match('/(?<major>\d+)\.(?<minor>\d+)(?:\.(?<patch>\d+))?/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
1010

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);
1212
}
1313
}
1414

@@ -23,11 +23,11 @@ function doUnmatchedAsNull(string $s): void {
2323
function unmatchedAsNullWithOptionalGroup(string $s): void {
2424
if (preg_match('/Price: (£|€)?\d+/', $s, $matches, PREG_UNMATCHED_AS_NULL)) {
2525
// 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);
2727
} else {
2828
assertType('array{}', $matches);
2929
}
30-
assertType("array{}|array{string, '£'|'€'|null}", $matches);
30+
assertType("array{}|array{non-falsy-string, '£'|'€'|null}", $matches);
3131
}
3232

3333
function bug11331a(string $url):void {
@@ -37,7 +37,7 @@ function bug11331a(string $url):void {
3737
(?<a>.+)
3838
)?
3939
(?<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);
4141
}
4242
}
4343

@@ -63,20 +63,20 @@ function bug11331c(string $url):void {
6363
([^/]+?)
6464
(?:\.git|/)?
6565
$}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);
6767
}
6868
}
6969

7070
class UnmatchedAsNullWithTopLevelAlternation {
7171
function doFoo(string $s): void {
7272
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
7474
}
7575
}
7676

7777
function doBar(string $s): void {
7878
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
8080
}
8181
}
8282
}
@@ -85,101 +85,101 @@ function (string $size): void {
8585
if (preg_match('/ab(\d){2,4}xx([0-9])?e?/', $size, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
8686
throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size));
8787
}
88-
assertType('array{string, numeric-string, numeric-string|null}', $matches);
88+
assertType('array{non-falsy-string, numeric-string, numeric-string|null}', $matches);
8989
};
9090

9191
function (string $size): void {
9292
if (preg_match('/a(\dAB){2}b(\d){2,4}([1-5])([1-5a-z])e?/', $size, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
9393
throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size));
9494
}
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);
9696
};
9797

9898
function (string $size): void {
9999
if (preg_match('/ab(ab(\d)){2,4}xx([0-9][a-c])?e?/', $size, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
100100
throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size));
101101
}
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);
103103
};
104104

105105
function (string $size): void {
106106
if (preg_match('/ab(\d+)e(\d?)/', $size, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
107107
throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size));
108108
}
109-
assertType("array{string, numeric-string, ''|numeric-string}", $matches);
109+
assertType("array{non-falsy-string, numeric-string, ''|numeric-string}", $matches);
110110
};
111111

112112
function (string $size): void {
113113
if (preg_match('/ab(?P<num>\d+)e?/', $size, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
114114
throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size));
115115
}
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);
117117
};
118118

119119
function (string $size): void {
120120
if (preg_match('/ab(\d\d)/', $size, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
121121
throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size));
122122
}
123-
assertType('array{string, non-falsy-string&numeric-string}', $matches);
123+
assertType('array{non-falsy-string, non-falsy-string&numeric-string}', $matches);
124124
};
125125

126126
function (string $size): void {
127127
if (preg_match('/ab(\d+\s)e?/', $size, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
128128
throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size));
129129
}
130-
assertType('array{string, non-falsy-string}', $matches);
130+
assertType('array{non-falsy-string, non-falsy-string}', $matches);
131131
};
132132

133133
function (string $size): void {
134134
if (preg_match('/ab(\s)e?/', $size, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
135135
throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size));
136136
}
137-
assertType('array{string, non-empty-string}', $matches);
137+
assertType('array{non-falsy-string, non-empty-string}', $matches);
138138
};
139139

140140
function (string $size): void {
141141
if (preg_match('/ab(\S)e?/', $size, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
142142
throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size));
143143
}
144-
assertType('array{string, non-empty-string}', $matches);
144+
assertType('array{non-falsy-string, non-empty-string}', $matches);
145145
};
146146

147147
function (string $size): void {
148148
if (preg_match('/ab(\S?)e?/', $size, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
149149
throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size));
150150
}
151-
assertType('array{string, string}', $matches);
151+
assertType('array{non-falsy-string, string}', $matches);
152152
};
153153

154154
function (string $size): void {
155155
if (preg_match('/ab(\S)?e?/', $size, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
156156
throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size));
157157
}
158-
assertType('array{string, non-empty-string|null}', $matches);
158+
assertType('array{non-falsy-string, non-empty-string|null}', $matches);
159159
};
160160

161161
function (string $size): void {
162162
if (preg_match('/ab(\d+\d?)e?/', $size, $matches, PREG_UNMATCHED_AS_NULL) !== 1) {
163163
throw new InvalidArgumentException(sprintf('Invalid size "%s"', $size));
164164
}
165-
assertType('array{string, numeric-string}', $matches);
165+
assertType('array{non-falsy-string, numeric-string}', $matches);
166166
};
167167

168168
function (string $s): void {
169169
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);
171171
}
172172
};
173173

174174
function (string $s): void {
175175
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);
177177
}
178178
};
179179

180180
function (string $s): void {
181181
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);
183183
}
184184
};
185185

@@ -201,22 +201,22 @@ function (string $s): void {
201201

202202
function (string $s): void {
203203
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);
205205
} else {
206206
assertType("array{}", $matches);
207207
}
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);
209209
};
210210

211211
function (string $s): void {
212212
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);
214214
}
215215
};
216216

217217
function (string $s): void {
218218
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);
220220
}
221221
};
222222

tests/PHPStan/Analyser/nsrt/bug-12211.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
function foo(string $text): void {
1212
assert(preg_match(REGEX, $text, $match) === 1);
13-
assertType('array{string, non-falsy-string}', $match);
13+
assertType('array{non-falsy-string, non-falsy-string}', $match);
1414
}
1515

1616

tests/PHPStan/Analyser/nsrt/bug11384.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class HelloWorld
1414
public function sayHello(string $s): void
1515
{
1616
if (preg_match('{(' . Bar::VAL . ')}', $s, $m)) {
17-
assertType("array{string, '3'}", $m);
17+
assertType("array{non-falsy-string, '3'}", $m);
1818
}
1919
}
2020
}

0 commit comments

Comments
 (0)