diff --git a/src/Psalm/Type/ParseTree.php b/src/Psalm/Type/ParseTree.php index 7c7147900..7a769722b 100644 --- a/src/Psalm/Type/ParseTree.php +++ b/src/Psalm/Type/ParseTree.php @@ -252,6 +252,10 @@ class ParseTree throw new TypeParseTreeException('Unexpected LHS of property'); } + if (!$current_parent instanceof ParseTree\ObjectLikeTree) { + throw new TypeParseTreeException('Saw : outside of object-like array'); + } + $new_parent_leaf = new ParseTree\ObjectLikePropertyTree($current_leaf->value, $current_parent); $new_parent_leaf->possibly_undefined = $last_token === '?'; $current_leaf->parent = $new_parent_leaf; diff --git a/tests/TypeParseTest.php b/tests/TypeParseTest.php index 8d9e1b432..783c6340d 100644 --- a/tests/TypeParseTest.php +++ b/tests/TypeParseTest.php @@ -493,6 +493,16 @@ class TypeParseTest extends TestCase Type::parseString('|array'); } + /** + * @expectedException \Psalm\Exception\TypeParseTreeException + * + * @return void + */ + public function testBadColonDash() + { + Type::parseString('array|string:-'); + } + /** * @expectedException \Psalm\Exception\TypeParseTreeException *