Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't update types of the outer scope when in an elseif conditional #9922

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,6 @@ public static function analyze(
$elseif_context->inside_loop,
new CodeLocation($statements_analyzer->getSource(), $elseif, $outer_context->include_location),
);

$updated_vars = [];

$outer_context->update(
$elseif_context,
$implied_outer_context,
false,
array_keys($negated_elseif_types),
$updated_vars,
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Internal/Codebase/InternalCallMapHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public function testGetcallmapReturnsAValidCallmap(): void
}

/**
* @return iterable<string, array{0: callable-string, 1: array<int|string, string>}>
* @return iterable<string, array{string, array<int|string, string>}>
*/
public function callMapEntryProvider(): iterable
{
Expand Down Expand Up @@ -404,7 +404,7 @@ private function isUnreflectableIgnored(string $functionName): bool
* @depends testGetcallmapReturnsAValidCallmap
* @dataProvider callMapEntryProvider
* @coversNothing
* @psalm-param callable-string $functionName
* @psalm-param string $functionName
* @param array<int|string, string> $callMapEntry
*/
public function testIgnoredFunctionsStillFail(string $functionName, array $callMapEntry): void
Expand Down Expand Up @@ -462,7 +462,7 @@ public function testIgnoredFunctionsStillFail(string $functionName, array $callM
* @depends testGetcallmapReturnsAValidCallmap
* @depends testIgnoresAreSortedAndUnique
* @dataProvider callMapEntryProvider
* @psalm-param callable-string $functionName
* @psalm-param string $functionName
* @param array<int|string, string> $callMapEntry
*/
public function testCallMapCompliesWithReflection(string $functionName, array $callMapEntry): void
Expand Down
17 changes: 17 additions & 0 deletions tests/TypeReconciliation/ConditionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3052,6 +3052,23 @@ function foo( $a, $b ) {
'$int' => 'int<97, 122>',
],
],
'short_circuited_conditional_test' => [
'code' => '<?php
/** @var ?stdClass $existing */
$existing = null;

/** @var bool $foo */
$foo = true;

if ($foo) {
} elseif ($existing === null) {
throw new \RuntimeException();
}
',
'assertions' => [
'$existing' => 'null|stdClass',
],
],
];
}

Expand Down
Loading