Skip to content

Commit

Permalink
Merge pull request #9922 from robchett/elseif_shouldnt_be_modifying_o…
Browse files Browse the repository at this point in the history
…uter_scope

Don't update types of the outer scope when in an elseif conditional
  • Loading branch information
orklah committed Jun 18, 2023
2 parents b515951 + 620c7cd commit e2dde5d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
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

0 comments on commit e2dde5d

Please sign in to comment.