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