1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #5108 - prevent crash on 0 type

This commit is contained in:
Matt Brown 2021-01-26 14:06:43 -05:00 committed by Daniil Gentili
parent 5da816f160
commit 4627065d1f
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 20 additions and 3 deletions

View File

@ -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] = [

View File

@ -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',
'<?php
for ($x = 0; $x <= 10; $x++) {}'
);
$codebase->file_provider->openFile('somefile.php');
$codebase->scanFiles();
$this->analyzeFile('somefile.php', new Context());
}
}