diff --git a/src/Psalm/Internal/Type/TypeTokenizer.php b/src/Psalm/Internal/Type/TypeTokenizer.php index a772bc7503e..9b4c6fdefda 100644 --- a/src/Psalm/Internal/Type/TypeTokenizer.php +++ b/src/Psalm/Internal/Type/TypeTokenizer.php @@ -9,9 +9,11 @@ use Psalm\Internal\Type\TypeAlias\InlineTypeAlias; use Psalm\Type; +use function array_slice; use function array_splice; use function array_unshift; use function count; +use function implode; use function in_array; use function is_numeric; use function preg_match; @@ -146,11 +148,9 @@ public static function tokenize(string $string_type, bool $ignore_space = true): $type_tokens[++$rtc] = [' ', $i - 1]; $type_tokens[++$rtc] = ['', $i]; } elseif ($was_space - && ($char === 'a' || $char === 'i') - && ($chars[$i + 1] ?? null) === 's' - && ($chars[$i + 2] ?? null) === ' ' + && in_array(implode('', array_slice($chars, $i, 3)), ['as ', 'is ', 'of ']) ) { - $type_tokens[++$rtc] = [$char . 's', $i - 1]; + $type_tokens[++$rtc] = [$char . $chars[$i+1], $i - 1]; $type_tokens[++$rtc] = ['', ++$i]; $was_char = false; continue; diff --git a/tests/TypeParseTest.php b/tests/TypeParseTest.php index 2ebae82ce4b..e092784ee81 100644 --- a/tests/TypeParseTest.php +++ b/tests/TypeParseTest.php @@ -935,6 +935,14 @@ public function testClassStringMap(): void ); } + public function testClassStringMapOf(): void + { + $this->assertSame( + 'class-string-map', + Type::parseString('class-string-map')->getId(false), + ); + } + public function testVeryLargeType(): void { $very_large_type = 'array{a: Closure():(array|null), b?: Closure():array, c?: Closure():array, d?: Closure():array, e?: Closure():(array{f: null|string, g: null|string, h: null|string, i: string, j: mixed, k: mixed, l: mixed, m: mixed, n: bool, o?: array{0: string}}|null), p?: Closure():(array{f: null|string, g: null|string, h: null|string, i: string, j: mixed, k: mixed, l: mixed, m: mixed, n: bool, o?: array{0: string}}|null), q: string, r?: Closure():(array|null), s: array}|null';