Skip to content

Commit b68a40d

Browse files
committed
fix class-string<*>&'foo' intersection
1 parent 05edb25 commit b68a40d

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎src/Type/Constant/ConstantStringType.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use PHPStan\Type\MixedType;
3535
use PHPStan\Type\NullType;
3636
use PHPStan\Type\ObjectType;
37+
use PHPStan\Type\ObjectWithoutClassType;
3738
use PHPStan\Type\StaticType;
3839
use PHPStan\Type\StringType;
3940
use PHPStan\Type\Traits\ConstantScalarTypeTrait;
@@ -146,6 +147,10 @@ private function export(string $value): string
146147
public function isSuperTypeOf(Type $type): TrinaryLogic
147148
{
148149
if ($type instanceof GenericClassStringType) {
150+
if ($this->isClassStringType()->no()) {
151+
return TrinaryLogic::createNo();
152+
}
153+
149154
$genericType = $type->getGenericType();
150155
if ($genericType instanceof MixedType) {
151156
return TrinaryLogic::createMaybe();

‎tests/PHPStan/Type/Constant/ConstantStringTypeTest.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ public function dataIsSuperTypeOf(): array
133133
new GenericClassStringType(new StaticType($reflectionProvider->getClass(Throwable::class))),
134134
TrinaryLogic::createMaybe(),
135135
],
136+
16 => [
137+
new ConstantStringType('array'),
138+
new GenericClassStringType(TemplateTypeFactory::create(
139+
TemplateTypeScope::createWithFunction('foo'),
140+
'T',
141+
null,
142+
TemplateTypeVariance::createInvariant(),
143+
)),
144+
TrinaryLogic::createNo(),
145+
],
136146
];
137147
}
138148

‎tests/PHPStan/Type/TypeCombinatorTest.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4162,6 +4162,19 @@ public function dataIntersect(): iterable
41624162
IntersectionType::class,
41634163
'array{a?: true, c?: true}&non-empty-array',
41644164
];
4165+
yield [
4166+
[
4167+
new ConstantStringType('array'),
4168+
new GenericClassStringType(TemplateTypeFactory::create(
4169+
TemplateTypeScope::createWithFunction('foo'),
4170+
'T',
4171+
null,
4172+
TemplateTypeVariance::createInvariant(),
4173+
)),
4174+
],
4175+
NeverType::class,
4176+
'*NEVER*=implicit',
4177+
];
41654178
yield [
41664179
[
41674180
new ConstantStringType(Exception::class),

0 commit comments

Comments
 (0)