Skip to content

Commit 0e8ab9c

Browse files
phpstan-botclaude
authored andcommitted
Add throw-points test for mixed~null (non-nullable) nullsafe method call
Add a companion test case where the left operand of ?-> is mixed~null (obtained via null-narrowing). Since the value can never be null, ?-> never short-circuits and variables assigned in arguments have Yes certainty. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 40d765c commit 0e8ab9c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/PHPStan/Analyser/nsrt/throw-points/php8/null-safe-method-call.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ function () {
4848
}
4949
};
5050

51+
function () {
52+
$result = doesntThrow();
53+
if ($result === null) {
54+
return;
55+
}
56+
// $result is mixed~null, so ?-> never short-circuits
57+
try {
58+
$result?->{$foo = 1}($bar = 2);
59+
} finally {
60+
assertVariableCertainty(TrinaryLogic::createYes(), $foo);
61+
assertVariableCertainty(TrinaryLogic::createYes(), $bar);
62+
}
63+
};
64+
5165
function () {
5266
try {
5367
maybeThrows()?->{$foo = 1}($bar = 2);

0 commit comments

Comments
 (0)