Skip to content

Commit 56ffcb2

Browse files
committed
Fix MixedType->equals(ErrorType)
1 parent 8971751 commit 56ffcb2

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
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 */
@@ -310,7 +311,7 @@ public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope)
310311

311312
public function equals(Type $type): bool
312313
{
313-
if (!$type instanceof self) {
314+
if (get_class($type) !== self::class) {
314315
return false;
315316
}
316317

tests/PHPStan/Type/MixedTypeTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,4 +1164,49 @@ public function testSubtractedHasOffsetValueType(MixedType $mixedType, Type $typ
11641164
);
11651165
}
11661166

1167+
/** @dataProvider dataEquals */
1168+
public function testEquals(MixedType $mixedType, Type $typeToCompare, bool $expectedResult): void
1169+
{
1170+
$this->assertSame(
1171+
$expectedResult,
1172+
$mixedType->equals($typeToCompare),
1173+
);
1174+
}
1175+
1176+
public function dataEquals(): array
1177+
{
1178+
return [
1179+
[
1180+
new MixedType(),
1181+
new MixedType(),
1182+
true,
1183+
],
1184+
[
1185+
new MixedType(true),
1186+
new MixedType(),
1187+
true,
1188+
],
1189+
[
1190+
new MixedType(),
1191+
new MixedType(true),
1192+
true,
1193+
],
1194+
[
1195+
new MixedType(),
1196+
new MixedType(true, new IntegerType()),
1197+
false,
1198+
],
1199+
[
1200+
new MixedType(),
1201+
new ErrorType(),
1202+
false,
1203+
],
1204+
[
1205+
new MixedType(true),
1206+
new ErrorType(),
1207+
false,
1208+
],
1209+
];
1210+
}
1211+
11671212
}

0 commit comments

Comments
 (0)