Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Treat array-shapes without keys as tuples #3872

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
zonuexe wants to merge 4 commits into phpstan:2.1.x
base: 2.1.x
Choose a base branch
Loading
from zonuexe:feature/keyless-constant-as-tuple
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Treat array-shapes without keys as tuples
  • Loading branch information
zonuexe committed Mar 11, 2025
commit 146bdbeb44109eeff7cdb0003d827e70fb59144a
7 changes: 7 additions & 0 deletions src/PhpDoc/TypeNodeResolver.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,13 @@ function (CallableTypeParameterNode $parameterNode) use ($nameScope, &$isVariadi
private function resolveArrayShapeNode(ArrayShapeNode $typeNode, NameScope $nameScope): Type
{
$builder = ConstantArrayTypeBuilder::createEmpty();
foreach ($typeNode->items as $itemNode) {
if ($itemNode->keyName !== null) {
$builder = ConstantArrayTypeBuilder::createEmptyIndeterminate();
break;
}
}

if (count($typeNode->items) > ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT) {
$builder->degradeToGeneralArray(true);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Constant/ConstantArrayTypeBuilder.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public static function createEmpty(): self
return new self([], [], [0], [], TrinaryLogic::createYes());
}

public static function createEmptyIndeterminate(): self
{
return new self([], [], [0], [], TrinaryLogic::createMaybe());
}

public static function createFromConstantArray(ConstantArrayType $startArrayType): self
{
$builder = new self(
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /