Skip to content

Commit 3d44fe9

Browse files
committed
fix union types
1 parent 8e5c640 commit 3d44fe9

3 files changed

Lines changed: 36 additions & 19 deletions

File tree

src/Analyser/TypeSpecifier.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,6 @@ private function getConditionalSpecifiedTypes(
15891589
$argumentExpr instanceof Node\Scalar
15901590
|| ($argumentExpr instanceof ConstFetch && in_array(strtolower($argumentExpr->name->toString()), ['true', 'false', 'null'], true))
15911591
)
1592-
&& $targetType->isConstantScalarValue()->yes()
15931592
) {
15941593
return null;
15951594
}

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ public function testImpossibleCheckTypeFunctionCall(): void
7474
'Call to function is_callable() with \'nonexistentFunction\' will always evaluate to false.',
7575
87,
7676
],
77-
[
78-
'Call to function is_numeric() with \'123\' will always evaluate to true.',
79-
102,
80-
],
81-
[
82-
'Call to function is_numeric() with \'blabla\' will always evaluate to false.',
83-
105,
84-
],
8577
[
8678
'Call to function is_numeric() with 123|float will always evaluate to true.',
8779
118,
@@ -231,19 +223,11 @@ public function testImpossibleCheckTypeFunctionCall(): void
231223
718,
232224
'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.',
233225
],
234-
[
235-
'Call to function is_numeric() with \'123\' will always evaluate to true.',
236-
718,
237-
],
238226
[
239227
'Call to function assert() with false will always evaluate to false.',
240228
719,
241229
'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.',
242230
],
243-
[
244-
'Call to function is_numeric() with \'blabla\' will always evaluate to false.',
245-
719,
246-
],
247231
[
248232
'Call to function assert() with true will always evaluate to true.',
249233
726,
@@ -1182,7 +1166,12 @@ public function testBug14177(): void
11821166
public function testBug13566(): void
11831167
{
11841168
$this->treatPhpDocTypesAsCertain = true;
1185-
$this->analyse([__DIR__ . '/data/bug-13566.php'], []);
1169+
$this->analyse([__DIR__ . '/data/bug-13566.php'], [
1170+
[
1171+
'Call to function is_numeric() with 123 will always evaluate to true.',
1172+
197,
1173+
],
1174+
]);
11861175
}
11871176

11881177
}

tests/PHPStan/Rules/Comparison/data/bug-13566.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php declare(strict_types = 1);
1+
<?php // lint >= 8.0
2+
3+
declare(strict_types = 1);
24

35
namespace Bug13566;
46

@@ -165,5 +167,32 @@ function test(): void
165167
{
166168
// send 404 header
167169
notFound(false);
170+
}
171+
172+
173+
class ReturnViaUnion
174+
{
175+
/**
176+
* @return ($exit is int ? void : never)
177+
*/
178+
public static function notFound(int|string $exit = 'hello world'): void
179+
{
180+
header('HTTP/1.1 404 Not Found', true, 404);
181+
182+
if (!is_int($exit)) {
183+
echo '404 Not Found';
184+
exit;
185+
}
186+
}
187+
188+
public function test(): void
189+
{
190+
// send 404 header
191+
self::notFound(0);
192+
}
193+
}
194+
168195

196+
$x = 123;
197+
if (is_numeric($x)) {
169198
}

0 commit comments

Comments
 (0)