Skip to content

Commit 91e63c5

Browse files
jiripudilondrejmirtes
authored andcommitted
test GenericObjectType contravariant subtyping
1 parent 08e484d commit 91e63c5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

tests/PHPStan/Type/Generic/GenericObjectTypeTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ public function dataIsSuperTypeOf(): array
9797
new GenericObjectType(C\Covariant::class, [new ObjectType('DateTimeInterface')]),
9898
TrinaryLogic::createMaybe(),
9999
],
100+
'contravariant with equal types' => [
101+
new GenericObjectType(C\Contravariant::class, [new ObjectType('DateTime')]),
102+
new GenericObjectType(C\Contravariant::class, [new ObjectType('DateTime')]),
103+
TrinaryLogic::createYes(),
104+
],
105+
'contravariant with sub type' => [
106+
new GenericObjectType(C\Contravariant::class, [new ObjectType('DateTimeInterface')]),
107+
new GenericObjectType(C\Contravariant::class, [new ObjectType('DateTime')]),
108+
TrinaryLogic::createMaybe(),
109+
],
110+
'contravariant with super type' => [
111+
new GenericObjectType(C\Contravariant::class, [new ObjectType('DateTime')]),
112+
new GenericObjectType(C\Contravariant::class, [new ObjectType('DateTimeInterface')]),
113+
TrinaryLogic::createYes(),
114+
],
100115
[
101116
new ObjectType(ReflectionClass::class),
102117
new GenericObjectType(ReflectionClass::class, [

tests/PHPStan/Type/Generic/data/generic-classes-c.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ interface Invariant {
99
/** @template-covariant T */
1010
interface Covariant {
1111
}
12+
13+
/** @template-contravariant T */
14+
interface Contravariant {
15+
}

0 commit comments

Comments
 (0)