Skip to content

Commit bce8093

Browse files
committed
Capture current ConstantArrayType inconsistencies related to sealedness
1 parent cc56ab5 commit bce8093

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,32 @@ public static function dataAccepts(): iterable
408408
]),
409409
TrinaryLogic::createMaybe(),
410410
];
411+
412+
yield [
413+
new ConstantArrayType([], []),
414+
new ConstantArrayType([], []),
415+
TrinaryLogic::createYes(),
416+
];
417+
418+
// empty array (with unknown sealedness) does not accept extra keys
419+
yield [
420+
new ConstantArrayType([], []),
421+
new ConstantArrayType([new ConstantStringType('a')], [new StringType()]),
422+
TrinaryLogic::createNo(),
423+
];
424+
425+
// non-empty array (with unknown sealedness) accepts extra keys
426+
yield [
427+
new ConstantArrayType([new ConstantStringType('a')], [new StringType()]),
428+
new ConstantArrayType([
429+
new ConstantStringType('a'),
430+
new ConstantStringType('b'),
431+
], [
432+
new StringType(),
433+
new IntegerType(),
434+
]),
435+
TrinaryLogic::createYes(),
436+
];
411437
}
412438

413439
#[DataProvider('dataAccepts')]
@@ -690,6 +716,26 @@ public static function dataIsSuperTypeOf(): iterable
690716
new ArrayType(new StringType(), new MixedType()),
691717
TrinaryLogic::createNo(),
692718
];
719+
720+
// empty array (with unknown sealedness) does not accept extra keys
721+
yield [
722+
new ConstantArrayType([], []),
723+
new ConstantArrayType([new ConstantStringType('a')], [new StringType()]),
724+
TrinaryLogic::createNo(),
725+
];
726+
727+
// non-empty array (with unknown sealedness) accepts extra keys
728+
yield [
729+
new ConstantArrayType([new ConstantStringType('a')], [new StringType()]),
730+
new ConstantArrayType([
731+
new ConstantStringType('a'),
732+
new ConstantStringType('b'),
733+
], [
734+
new StringType(),
735+
new IntegerType(),
736+
]),
737+
TrinaryLogic::createYes(),
738+
];
693739
}
694740

695741
#[DataProvider('dataIsSuperTypeOf')]

0 commit comments

Comments
 (0)