Skip to content
Permalink
Browse files

Fix #2552 - add parse error when encountering empty array values

  • Loading branch information
muglug committed Jan 4, 2020
1 parent 8ecb855 commit 37810b5a4412bcd57871536f1b19404ef90cef9e
Showing with 21 additions and 1 deletion.
  1. +8 −1 src/Psalm/Internal/Analyzer/Statements/Expression/ArrayAnalyzer.php
  2. +13 −0 tests/BadFormatTest.php
@@ -62,7 +62,14 @@ public static function analyze(

foreach ($stmt->items as $int_offset => $item) {
if ($item === null) {
continue;
\Psalm\IssueBuffer::add(
new \Psalm\Issue\ParseError(
'Array element cannot be empty',
new CodeLocation($statements_analyzer, $stmt)
)
);

return false;
}

if (ExpressionAnalyzer::analyze($statements_analyzer, $item->value, $context) === false) {
@@ -106,4 +106,17 @@ interface B {}'

$this->analyzeFile('somefile.php', new Context());
}

public function testBadArray()
{
$this->expectExceptionMessage('ParseError - somefile.php:2');
$this->expectException(\Psalm\Exception\CodeException::class);
$this->addFile(
'somefile.php',
'<?php
[1,,2];'
);

$this->analyzeFile('somefile.php', new Context());
}
}

0 comments on commit 37810b5

Please sign in to comment.
You can’t perform that action at this time.