Skip to content

Commit 561aa97

Browse files
committed
Fix CI failures [claude-ci-fix]
Automated fix attempt 2 for CI failures.
1 parent efecc10 commit 561aa97

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@
174174
use PHPStan\Type\Constant\ConstantIntegerType;
175175
use PHPStan\Type\Constant\ConstantStringType;
176176
use PHPStan\Type\FileTypeMapper;
177-
use PHPStan\Type\FloatType;
178177
use PHPStan\Type\GeneralizePrecision;
179178
use PHPStan\Type\Generic\TemplateTypeHelper;
180179
use PHPStan\Type\Generic\TemplateTypeMap;
@@ -6369,7 +6368,7 @@ private function processAssignVar(
63696368
$nativeProperty = $declaringClass->getNativeProperty($propertyName);
63706369
$propertyNativeType = $nativeProperty->getNativeType();
63716370
// Widen property type to accept int for float properties (PHP allows int-to-float coercion without TypeError)
6372-
$propertyNativeTypeForAccepts = $propertyNativeType->isSuperTypeOf(new FloatType())->yes()
6371+
$propertyNativeTypeForAccepts = !$propertyNativeType->isFloat()->no()
63736372
? TypeCombinator::union($propertyNativeType, new IntegerType())
63746373
: $propertyNativeType;
63756374
if (

tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,12 @@ public function testPropertyHooks(): void
645645

646646
public function testBug9146(): void
647647
{
648-
$this->analyse([__DIR__ . '/data/bug-9146.php'], []);
648+
$this->analyse([__DIR__ . '/data/bug-9146.php'], [
649+
[
650+
'Dead catch - TypeError is never thrown in the try block.',
651+
52,
652+
],
653+
]);
649654
}
650655

651656
}

tests/PHPStan/Rules/Exceptions/data/bug-9146.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,32 @@ public function setAmount(mixed $value): void
4040
}
4141
}
4242
}
43+
44+
// Dead catch: int assigned to ?float, PHP coerces int to float without TypeError
45+
final class FloatNullCoercion
46+
{
47+
public ?float $amount;
48+
public function setAmount(int $value): void
49+
{
50+
try {
51+
$this->amount = $value;
52+
} catch (\TypeError $e) { // error: Dead catch - TypeError is never thrown in the try block.
53+
echo "caught";
54+
}
55+
}
56+
}
57+
58+
// Not dead: int|string assigned to int, string part could throw TypeError
59+
final class PartialTypeMatch
60+
{
61+
public int $number;
62+
/** @param int|string $value */
63+
public function setNumber($value): void
64+
{
65+
try {
66+
$this->number = $value;
67+
} catch (\TypeError $e) {
68+
echo "caught";
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)