From e0778fcc11614baa89cb5a912e7224efc7932e8c Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 29 Nov 2023 13:32:45 +0100 Subject: [PATCH] Fix parsing of array keys with @ --- src/Psalm/Internal/Type/ParseTreeCreator.php | 6 +++++- tests/TypeAnnotationTest.php | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Type/ParseTreeCreator.php b/src/Psalm/Internal/Type/ParseTreeCreator.php index 737b5ac3f..587d2fcd8 100644 --- a/src/Psalm/Internal/Type/ParseTreeCreator.php +++ b/src/Psalm/Internal/Type/ParseTreeCreator.php @@ -830,7 +830,11 @@ final class ParseTreeCreator $nexter_token = $this->t + 1 < $this->type_token_count ? $this->type_tokens[$this->t + 1] : null; - if ($nexter_token && strpos($nexter_token[0], '@') !== false) { + if ($nexter_token + && strpos($nexter_token[0], '@') !== false + && $type_token[0] !== 'list' + && $type_token[0] !== 'array' + ) { $this->t = $this->type_token_count; if ($type_token[0] === '$this') { $type_token[0] = 'static'; diff --git a/tests/TypeAnnotationTest.php b/tests/TypeAnnotationTest.php index 07058f219..bdec0ba36 100644 --- a/tests/TypeAnnotationTest.php +++ b/tests/TypeAnnotationTest.php @@ -15,6 +15,14 @@ class TypeAnnotationTest extends TestCase public function providerValidCodeParse(): iterable { return [ + 'atInArrayKey' => [ + 'code' => ' $v + */ + function a(array $v): void {}', + ], 'typeAliasBeforeClass' => [ 'code' => '