diff --git a/src/Ast/Type/ArrayShapeUnsealedTypeNode.php b/src/Ast/Type/ArrayShapeUnsealedTypeNode.php index b6c36bb7..8a69b398 100644 --- a/src/Ast/Type/ArrayShapeUnsealedTypeNode.php +++ b/src/Ast/Type/ArrayShapeUnsealedTypeNode.php @@ -11,10 +11,11 @@ class ArrayShapeUnsealedTypeNode implements Node use NodeAttributes; - public TypeNode $valueType; - + // declared in source order: the format-preserving printer walks the properties in this order public ?TypeNode $keyType = null; + public TypeNode $valueType; + public function __construct(TypeNode $valueType, ?TypeNode $keyType) { $this->valueType = $valueType; diff --git a/tests/PHPStan/Printer/PrinterTest.php b/tests/PHPStan/Printer/PrinterTest.php index 242965d2..e8608821 100644 --- a/tests/PHPStan/Printer/PrinterTest.php +++ b/tests/PHPStan/Printer/PrinterTest.php @@ -3060,6 +3060,40 @@ public function enterNode(Node $node) }, ]; + + yield [ + '/** @return array{foo: Foo, ...} */', + '/** @return array{foo: Bar, ...} */', + new class extends AbstractNodeVisitor { + + public function enterNode(Node $node) + { + if ($node instanceof IdentifierTypeNode && $node->name === 'Foo') { + return new IdentifierTypeNode('Bar'); + } + + return $node; + } + + }, + ]; + + yield [ + '/** @return array{foo: int, ...< Foo , Baz >} */', + '/** @return array{foo: int, ...< Bar , Baz >} */', + new class extends AbstractNodeVisitor { + + public function enterNode(Node $node) + { + if ($node instanceof IdentifierTypeNode && $node->name === 'Foo') { + $node->name = 'Bar'; + } + + return $node; + } + + }, + ]; } /**