Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PhpdocArrayTypeFixer - JIT stack limit exhausted #7895

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/DocBlock/TypeExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ final class TypeExpression
(?:
\h*,\h*
(?&callable_argument)
)*
)*+
(?:\h*,\h*)?
|)
\h*\)
Expand All @@ -125,7 +125,7 @@ final class TypeExpression
(?:
\h*,\h*
(?&types_inner)
)*
)*+
(?:\h*,\h*)?
)
\h*>
Expand Down Expand Up @@ -196,13 +196,13 @@ final class TypeExpression
(\h*\[\h*\])*
)
(?:(?=1)0
(?<types_inner>
(?<types_inner>(?>
(?&type)
(?:
\h*[|&]\h*
(?&type)
)*+
)
))
|)
)';

Expand Down
27 changes: 13 additions & 14 deletions tests/DocBlock/TypeExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ public static function provideGetTypesCases(): iterable

yield ['OBJECT { x: 1 }'];

yield ['array{a: int, b: int, with-dash: int}'];

yield ['callable'];

yield ['callable(string)'];
Expand Down Expand Up @@ -249,11 +251,11 @@ public static function provideGetTypesCases(): iterable

yield ['\'a\\\'s"\\\\\n\r\t\'|"b\\"s\'\\\\\n\r\t"', ['\'a\\\'s"\\\\\n\r\t\'', '"b\\"s\'\\\\\n\r\t"']];

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 ['string'.str_repeat('[]', 128)];
kubawerlos marked this conversation as resolved.
Show resolved Hide resolved

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 [str_repeat('array<', 128).'string'.str_repeat('>', 128)];

yield [self::createHugeArrayShapeType()];
yield [self::makeLongArrayShapeType()];
}

public static function provideGetConstTypesCases(): iterable
Expand Down Expand Up @@ -401,7 +403,7 @@ public static function provideParseInvalidExceptionCases(): iterable

yield 'generic Closure with non-identifier template argument' => ['Closure<A|B>(): void'];

yield [substr(self::createHugeArrayShapeType(), 0, -1)];
yield [substr(self::makeLongArrayShapeType(), 0, -1)];
}

public function testHugeType(): void
Expand Down Expand Up @@ -923,18 +925,15 @@ public static function provideSortTypesCases(): iterable
];
}

private static function createHugeArrayShapeType(): string
private static function makeLongArrayShapeType(): 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 'array{'.implode(
', ',
array_map(
static fn (int $k): string => sprintf('key%sno%d: int', 0 === $k % 2 ? '-' : '_', $k),
range(1, 1_000),
),
);
).'}';
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/Fixer/Phpdoc/PhpdocArrayTypeFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,16 @@ public static function provideFixCases(): iterable
'<?php /** @var (Foo&Bar)|array<Baz> */',
'<?php /** @var (Foo&Bar)|Baz[] */',
];

$expected = $input = 'string';
for ($i = 0; $i < 128; ++$i) {
$expected = 'array<'.$expected.'>';
$input .= '[]';
}

yield [
sprintf('<?php /** @var %s */', $expected),
sprintf('<?php /** @var %s */', $input),
];
}
}