Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Ast/Type/ArrayShapeUnsealedTypeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ class ArrayShapeUnsealedTypeNode implements Node

use NodeAttributes;

public TypeNode $valueType;

// declared in the order of the source, the format-preserving printer reprints the subnodes in this order
public ?TypeNode $keyType = null;

public TypeNode $valueType;

public function __construct(TypeNode $valueType, ?TypeNode $keyType)
{
$this->valueType = $valueType;
Expand Down
52 changes: 52 additions & 0 deletions tests/PHPStan/Printer/PrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,58 @@ public function enterNode(Node $node)
},
];

yield [
'/** @return array{foo: int, ...<string, int>} */',
'/** @return array{foo: int, ...<string, int>} */',
new class extends AbstractNodeVisitor {

},
];

yield [
'/** @return array{...<string, int>} */',
'/** @return array{...<string, int>} */',
new class extends AbstractNodeVisitor {

},
];

yield [
'/** @return array{foo: int, ...<string, int>} */',
'/** @return array{foo: int, ...<string, bool>} */',
new class extends AbstractNodeVisitor {

public function enterNode(Node $node)
{
if ($node instanceof ArrayShapeNode) {
assert($node->unsealedType !== null);
$node->unsealedType->valueType = new IdentifierTypeNode('bool');
}

return $node;
}

},
];

yield [
'/** @return array{foo: int, ...<string, int>} */',
'/** @return array{foo: int, ...<int, int>} */',
new class extends AbstractNodeVisitor {

public function enterNode(Node $node)
{
if ($node instanceof ArrayShapeNode) {
assert($node->unsealedType !== null);
$node->unsealedType->keyType = new IdentifierTypeNode('int');
}

return $node;
}

},
];

yield [
'/** @return array{foo: int, ...<string>} */',
'/** @return array{foo: int, ...<int, string>} */',
Expand Down
Loading