1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00

Fix #4837 - bind correct static class when checking mixin types

This commit is contained in:
Matt Brown 2020-12-14 22:51:32 -05:00 committed by Daniil Gentili
parent cc06cb53f5
commit 4416da85e7
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 42 additions and 3 deletions

View File

@ -483,6 +483,18 @@ class ClassAnalyzer extends ClassLikeAnalyzer
/** @var non-empty-array<int, Type\Atomic\TTemplateParam|Type\Atomic\TNamedObject> $mixins */ /** @var non-empty-array<int, Type\Atomic\TTemplateParam|Type\Atomic\TNamedObject> $mixins */
$mixins = array_merge($storage->templatedMixins, $storage->namedMixins); $mixins = array_merge($storage->templatedMixins, $storage->namedMixins);
$union = new Type\Union($mixins); $union = new Type\Union($mixins);
$static_self = new Type\Atomic\TNamedObject($storage->name);
$static_self->was_static = true;
$union = \Psalm\Internal\Type\TypeExpander::expandUnion(
$codebase,
$union,
$storage->name,
$static_self,
null
);
$union->check( $union->check(
$this, $this,
new CodeLocation( new CodeLocation(

View File

@ -259,7 +259,7 @@ class TypeChecker extends NodeVisitor
$codebase, $codebase,
$expected_type_param, $expected_type_param,
$defining_class, $defining_class,
$defining_class, null,
null null
); );
@ -267,7 +267,7 @@ class TypeChecker extends NodeVisitor
$codebase, $codebase,
$type_param, $type_param,
$defining_class, $defining_class,
$defining_class, null,
null null
); );

View File

@ -561,6 +561,33 @@ class MixinAnnotationTest extends TestCase
$bar->foo();' $bar->foo();'
], ],
'templatedMixinBindStatic' => [
'<?php
/**
* @template-covariant TModel of Model
*/
class QueryBuilder {
/**
* @return list<TModel>
*/
public function getInner() {
return [];
}
}
/**
* @mixin QueryBuilder<static>
*/
abstract class Model {}
class FooModel extends Model {}
$f = new FooModel();
$g = $f->getInner();',
[
'$g' => 'list<FooModel>',
]
],
]; ];
} }