Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Type/StrictMixedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Generic\TemplateMixedType;
use PHPStan\Type\Generic\TemplateStrictMixedType;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Generic\TemplateTypeVariance;
use PHPStan\Type\Traits\NonArrayTypeTrait;
Expand Down Expand Up @@ -61,7 +62,7 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult

public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult
{
if ($acceptingType instanceof self) {
if ($acceptingType instanceof self && !$acceptingType instanceof TemplateStrictMixedType) {
return AcceptsResult::createYes();
}
if ($acceptingType instanceof MixedType && !$acceptingType instanceof TemplateMixedType) {
Expand All @@ -78,7 +79,7 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult

public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
{
if ($otherType instanceof self) {
if ($otherType instanceof self && !$otherType instanceof TemplateStrictMixedType) {
return IsSuperTypeOfResult::createYes();
}
if ($otherType instanceof MixedType && !$otherType instanceof TemplateMixedType) {
Expand Down
4 changes: 4 additions & 0 deletions tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ public function testBug11935WithCheckExplicitMixed(): void
{
$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-11935.php'], [
[
'Parameter #1 of callable callable(A): A expects A, mixed given.',
16,
],
[
'Parameter #1 of callable callable(Bug11935\Inv<A>): Bug11935\Inv<A> expects Bug11935\Inv<A>, Bug11935\Inv<mixed> given.',
34,
Expand Down
62 changes: 62 additions & 0 deletions tests/PHPStan/Type/StrictMixedTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php declare(strict_types = 1);

namespace PHPStan\Type;

use PHPStan\Testing\PHPStanTestCase;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Generic\TemplateStrictMixedType;
use PHPStan\Type\Generic\TemplateTypeParameterStrategy;
use PHPStan\Type\Generic\TemplateTypeScope;
use PHPStan\Type\Generic\TemplateTypeVariance;
use PHPUnit\Framework\Attributes\DataProvider;
use function sprintf;

class StrictMixedTypeTest extends PHPStanTestCase
{

public static function dataIsSubTypeOf(): array
{
return [
[
new StrictMixedType(),
new StrictMixedType(),
TrinaryLogic::createYes(),
],
[
new StrictMixedType(),
new TemplateStrictMixedType(
scope: TemplateTypeScope::createWithFunction('identity'),
templateTypeStrategy: new TemplateTypeParameterStrategy(),
templateTypeVariance: TemplateTypeVariance::createInvariant(),
name: 'A',
bound: new StrictMixedType(),
default: null,
),
TrinaryLogic::createMaybe(),
],
];
}

#[DataProvider('dataIsSubTypeOf')]
public function testIsSubTypeOf(StrictMixedType $type, Type $otherType, TrinaryLogic $expectedResult): void
{
$actualResult = $type->isSubTypeOf($otherType);
$this->assertSame(
$expectedResult->describe(),
$actualResult->describe(),
sprintf('%s -> isSubTypeOf(%s)', $type->describe(VerbosityLevel::precise()), $otherType->describe(VerbosityLevel::precise())),
);
}

#[DataProvider('dataIsSubTypeOf')]
public function testIsSubTypeOfInversed(StrictMixedType $type, Type $otherType, TrinaryLogic $expectedResult): void
{
$actualResult = $otherType->isSuperTypeOf($type);
$this->assertSame(
$expectedResult->describe(),
$actualResult->describe(),
sprintf('%s -> isSuperTypeOf(%s)', $otherType->describe(VerbosityLevel::precise()), $type->describe(VerbosityLevel::precise())),
);
}

}
Loading