Skip to content

Commit 0210d45

Browse files
committed
Fix ConstantArrayType::isSuperTypeOf()
1 parent bc81fe9 commit 0210d45

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

Diff for: src/Type/Constant/ConstantArrayType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public function isSuperTypeOf(Type $type): TrinaryLogic
405405
return TrinaryLogic::createNo();
406406
}
407407

408-
return $result->and($isKeySuperType, $this->getIterableValueType()->isSuperTypeOf($type->getIterableKeyType()));
408+
return $result->and($isKeySuperType, $this->getIterableValueType()->isSuperTypeOf($type->getIterableValueType()));
409409
}
410410

411411
if ($type instanceof CompoundType) {

Diff for: tests/PHPStan/Rules/PhpDoc/WrongVariableNameInVarTagRuleTest.php

-4
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,6 @@ public function testRule(): void
140140
'PHPDoc tag @var above a function has no effect.',
141141
313,
142142
],
143-
[
144-
"PHPDoc tag @var with type array<int, mixed> is not subtype of native type array{: 'empty', 1: '1'}.",
145-
324,
146-
],
147143
]);
148144
}
149145

Diff for: tests/PHPStan/Type/ArrayTypeTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ public function dataIsSuperTypeOf(): array
7171
new IntersectionType([new ArrayType(new IntegerType(), new StringType()), new OversizedArrayType()]),
7272
TrinaryLogic::createYes(),
7373
],
74+
[
75+
new ArrayType(new StringType(), new MixedType()),
76+
new ConstantArrayType([
77+
new ConstantStringType('a'),
78+
new ConstantStringType('b'),
79+
], [
80+
new IntegerType(),
81+
new UnionType([new IntegerType(), new NullType()]),
82+
]),
83+
TrinaryLogic::createYes(),
84+
],
7485
];
7586
}
7687

Diff for: tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php

+37
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PHPStan\Type\IterableType;
1919
use PHPStan\Type\MixedType;
2020
use PHPStan\Type\NeverType;
21+
use PHPStan\Type\NullType;
2122
use PHPStan\Type\ObjectType;
2223
use PHPStan\Type\StringType;
2324
use PHPStan\Type\Type;
@@ -654,6 +655,42 @@ public function dataIsSuperTypeOf(): iterable
654655
], [1], [0]),
655656
TrinaryLogic::createMaybe(),
656657
];
658+
659+
yield [
660+
new ConstantArrayType([
661+
new ConstantStringType('a'),
662+
new ConstantStringType('b'),
663+
], [
664+
new IntegerType(),
665+
new UnionType([new IntegerType(), new NullType()]),
666+
]),
667+
new ArrayType(new StringType(), new MixedType()),
668+
TrinaryLogic::createMaybe(),
669+
];
670+
671+
yield [
672+
new ConstantArrayType([
673+
new ConstantStringType('a'),
674+
new ConstantStringType('b'),
675+
], [
676+
new IntegerType(),
677+
new UnionType([new IntegerType(), new NullType()]),
678+
]),
679+
new ArrayType(new StringType(), new StringType()),
680+
TrinaryLogic::createNo(),
681+
];
682+
683+
yield [
684+
new ConstantArrayType([
685+
new ConstantIntegerType(1),
686+
new ConstantIntegerType(2),
687+
], [
688+
new IntegerType(),
689+
new UnionType([new IntegerType(), new NullType()]),
690+
]),
691+
new ArrayType(new StringType(), new MixedType()),
692+
TrinaryLogic::createNo(),
693+
];
657694
}
658695

659696
/**

0 commit comments

Comments
 (0)