Skip to content

Commit 425b239

Browse files
phil-nelsonfelixfbecker
authored andcommitted
fix(DefinitionResolver): fix crash on unknown foreach type (#562)
Fix when unknown type is found in foreach expression
1 parent a0caf8d commit 425b239

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

fixtures/completion/foreach.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ public function test() { }
3535
foreach ($bar->test() as $value) {
3636
$
3737
}
38+
39+
foreach ($unknownArray as $unknown) {
40+
$unkno

src/DefinitionResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ public function getTypeFromNode($node)
11221122
if ($collectionType instanceof Types\Array_) {
11231123
return $collectionType->getValueType();
11241124
}
1125+
return new Types\Mixed_();
11251126
}
11261127

11271128
// PROPERTIES, CONSTS, CLASS CONSTS, ASSIGNMENT EXPRESSIONS

tests/Server/TextDocument/CompletionTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,21 @@ public function foreachProvider(): array
691691
),
692692
]
693693
],
694+
'foreach unknown type' => [
695+
new Position(39, 10),
696+
[
697+
new CompletionItem(
698+
'$unknown',
699+
CompletionItemKind::VARIABLE,
700+
'mixed',
701+
null,
702+
null,
703+
null,
704+
null,
705+
new TextEdit(new Range(new Position(39, 10), new Position(39, 10)), 'wn')
706+
),
707+
]
708+
],
694709
];
695710
}
696711

0 commit comments

Comments
 (0)