Просмотр исходного кода

fix: `TypeExpression` - fix "JIT stack limit exhausted" error (#7843)

Kuba Werłos 11 месяцев назад
Родитель
Сommit
5380db3aa1
2 измененных файлов с 19 добавлено и 1 удалено
  1. 1 1
      src/DocBlock/TypeExpression.php
  2. 18 0
      tests/DocBlock/TypeExpressionTest.php

+ 1 - 1
src/DocBlock/TypeExpression.php

@@ -64,7 +64,7 @@ final class TypeExpression
                         (?:
                             \h*,\h*
                             (?&array_shape_inner)
-                        )*
+                        )*+
                         (?:\h*,\h*)?
                     |)
                     \h*\}

+ 18 - 0
tests/DocBlock/TypeExpressionTest.php

@@ -252,6 +252,8 @@ final class TypeExpressionTest extends TestCase
         yield ['array{a: int, b: int, c: int, d: int, e: int, f: int, g: int, h: int, i: int, j: int, with-dash: int}'];
 
         yield ['array{a: int, b: int, c: int, d: int, e: int, f: int, g: int, h: int, i: int, j: int, k: int, l: int, with-dash: int}'];
+
+        yield [self::createHugeArrayShapeType()];
     }
 
     public static function provideGetConstTypesCases(): iterable
@@ -398,6 +400,8 @@ final class TypeExpressionTest extends TestCase
         yield 'generic Closure with no arguments' => ['Closure<>(): void'];
 
         yield 'generic Closure with non-identifier template argument' => ['Closure<A|B>(): void'];
+
+        yield [substr(self::createHugeArrayShapeType(), 0, -1)];
     }
 
     public function testHugeType(): void
@@ -919,6 +923,20 @@ final class TypeExpressionTest extends TestCase
         ];
     }
 
+    private static function createHugeArrayShapeType(): string
+    {
+        return sprintf(
+            'array{%s}',
+            implode(
+                ', ',
+                array_map(
+                    static fn (int $k): string => sprintf('key%sno%d: int', 0 === $k % 2 ? '-' : '_', $k),
+                    range(1, 1_000),
+                ),
+            ),
+        );
+    }
+
     /**
      * Return type is recursive.
      *