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:
parent
cc06cb53f5
commit
4416da85e7
@ -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(
|
||||
|
@ -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
|
||||
);
|
||||
|
||||
|
@ -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>',
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user