1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +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 */
$mixins = array_merge($storage->templatedMixins, $storage->namedMixins);
$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(
$this,
new CodeLocation(

View File

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

View File

@ -554,13 +554,40 @@ class MixinAnnotationTest extends TestCase
*/
class Bar
{
}
$bar = new Bar();
$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>',
]
],
];
}