From 4627065d1fbc429b234c0891e30ee8b1587b1e9f Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Tue, 26 Jan 2021 14:06:43 -0500 Subject: [PATCH] Fix #5108 - prevent crash on 0 type --- src/Psalm/Internal/Codebase/Analyzer.php | 6 +++--- tests/LanguageServer/CompletionTest.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/Codebase/Analyzer.php b/src/Psalm/Internal/Codebase/Analyzer.php index 9ac2464c0..276dff853 100644 --- a/src/Psalm/Internal/Codebase/Analyzer.php +++ b/src/Psalm/Internal/Codebase/Analyzer.php @@ -1144,7 +1144,7 @@ class Analyzer string $node_type, PhpParser\Node $parent_node = null ): void { - if (!$node_type) { + if ($node_type === '') { throw new \UnexpectedValueException('non-empty node_type expected'); } @@ -1161,8 +1161,8 @@ class Analyzer string $reference, int $argument_number ): void { - if (!$reference) { - throw new \UnexpectedValueException('non-empty node_type expected'); + if ($reference === '') { + throw new \UnexpectedValueException('non-empty reference expected'); } $this->argument_map[$file_path][$start_position] = [ diff --git a/tests/LanguageServer/CompletionTest.php b/tests/LanguageServer/CompletionTest.php index 3b5a80d49..a99046f09 100644 --- a/tests/LanguageServer/CompletionTest.php +++ b/tests/LanguageServer/CompletionTest.php @@ -798,4 +798,21 @@ class CompletionTest extends \Psalm\Tests\TestCase $completion_items = $codebase->getCompletionItemsForClassishThing($completion_data[0], $completion_data[1]); $this->assertCount(2, $completion_items); } + + public function testNoCrashOnLoopId(): void + { + $codebase = $this->project_analyzer->getCodebase(); + $config = $codebase->config; + $config->throw_exception = false; + + $this->addFile( + 'somefile.php', + 'file_provider->openFile('somefile.php'); + $codebase->scanFiles(); + $this->analyzeFile('somefile.php', new Context()); + } }