Skip to content

Commit ed7eb47

Browse files
authored
Fix MixedType->equals(ErrorType)
1 parent 7e732bf commit ed7eb47

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

src/Type/MixedType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
3838
use PHPStan\Type\Traits\NonGenericTypeTrait;
3939
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
40+
use function get_class;
4041
use function sprintf;
4142

4243
/** @api */
@@ -319,7 +320,7 @@ public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope)
319320

320321
public function equals(Type $type): bool
321322
{
322-
if (!$type instanceof self) {
323+
if (get_class($type) !== static::class) {
323324
return false;
324325
}
325326

tests/PHPStan/Generics/TemplateTypeFactoryTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ public static function dataCreate(): array
5656
null,
5757
TemplateTypeVariance::createInvariant(),
5858
),
59-
new MixedType(),
59+
TemplateTypeFactory::create(
60+
TemplateTypeScope::createWithFunction('a'),
61+
'U',
62+
null,
63+
TemplateTypeVariance::createInvariant(),
64+
),
6065
],
6166
[
6267
new UnionType([

tests/PHPStan/Type/MixedTypeTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,4 +1129,50 @@ public function testSubtractedHasOffsetValueType(MixedType $mixedType, Type $typ
11291129
);
11301130
}
11311131

1132+
/** @dataProvider dataEquals */
1133+
public function testEquals(MixedType $mixedType, Type $typeToCompare, bool $expectedResult): void
1134+
{
1135+
$this->assertSame(
1136+
$expectedResult,
1137+
$mixedType->equals($typeToCompare),
1138+
sprintf('%s -> equals(%s)', $mixedType->describe(VerbosityLevel::precise()), $typeToCompare->describe(VerbosityLevel::precise())),
1139+
);
1140+
}
1141+
1142+
public function dataEquals(): array
1143+
{
1144+
return [
1145+
[
1146+
new MixedType(),
1147+
new MixedType(),
1148+
true,
1149+
],
1150+
[
1151+
new MixedType(true),
1152+
new MixedType(),
1153+
true,
1154+
],
1155+
[
1156+
new MixedType(),
1157+
new MixedType(true),
1158+
true,
1159+
],
1160+
[
1161+
new MixedType(),
1162+
new MixedType(true, new IntegerType()),
1163+
false,
1164+
],
1165+
[
1166+
new MixedType(),
1167+
new ErrorType(),
1168+
false,
1169+
],
1170+
[
1171+
new MixedType(true),
1172+
new ErrorType(),
1173+
false,
1174+
],
1175+
];
1176+
}
1177+
11321178
}

0 commit comments

Comments
 (0)