Skip to content
Merged
3 changes: 2 additions & 1 deletion src/Type/MixedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
use PHPStan\Type\Traits\NonGenericTypeTrait;
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
use function get_class;
use function sprintf;

/** @api */
Expand Down Expand Up @@ -310,7 +311,7 @@ public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope)

public function equals(Type $type): bool
{
if (!$type instanceof self) {
if (get_class($type) !== static::class) {
return false;
}

Expand Down
7 changes: 6 additions & 1 deletion tests/PHPStan/Generics/TemplateTypeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ public function dataCreate(): array
null,
TemplateTypeVariance::createInvariant(),
),
new MixedType(),
TemplateTypeFactory::create(
TemplateTypeScope::createWithFunction('a'),
'U',
null,
TemplateTypeVariance::createInvariant(),
),
],
[
new UnionType([
Expand Down
46 changes: 46 additions & 0 deletions tests/PHPStan/Type/MixedTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1164,4 +1164,50 @@ public function testSubtractedHasOffsetValueType(MixedType $mixedType, Type $typ
);
}

/** @dataProvider dataEquals */
public function testEquals(MixedType $mixedType, Type $typeToCompare, bool $expectedResult): void
{
$this->assertSame(
$expectedResult,
$mixedType->equals($typeToCompare),
sprintf('%s -> equals(%s)', $mixedType->describe(VerbosityLevel::precise()), $typeToCompare->describe(VerbosityLevel::precise())),
);
}

public function dataEquals(): array
{
return [
[
new MixedType(),
new MixedType(),
true,
],
[
new MixedType(true),
new MixedType(),
true,
],
[
new MixedType(),
new MixedType(true),
true,
],
[
new MixedType(),
new MixedType(true, new IntegerType()),
false,
],
[
new MixedType(),
new ErrorType(),
false,
],
[
new MixedType(true),
new ErrorType(),
false,
],
];
}

}
Loading