Skip to content
Permalink
Browse files

Fix #2471 - don’t erroneously template class-strings

  • Loading branch information
muglug committed Dec 15, 2019
1 parent 1a92e98 commit 72f3c306d7f1448d677afa3071e263d7581c4137
@@ -875,6 +875,8 @@ public static function analyzeInstance(
$has_valid_assignment_value_type = true;
}

var_dump($assignment_value_type->getId() . ' ' . $class_property_type->getId());

$invalid_assignment_value_types[] = $class_property_type->getId();
} else {
$has_valid_assignment_value_type = true;
@@ -449,9 +449,7 @@ public static function localizeType(
$type = clone $type;

foreach ($type->getTypes() as $key => $atomic_type) {
if ($atomic_type instanceof Type\Atomic\TTemplateParam
|| $atomic_type instanceof Type\Atomic\TTemplateParamClass
) {
if ($atomic_type instanceof Type\Atomic\TTemplateParam) {
if ($atomic_type->defining_class === $base_fq_class_name) {
if (isset($extends[$base_fq_class_name][$atomic_type->param_name])) {
$extended_param = $extends[$base_fq_class_name][$atomic_type->param_name];
@@ -466,6 +464,16 @@ public static function localizeType(
}
}

if ($atomic_type instanceof Type\Atomic\TTemplateParamClass) {
if ($atomic_type->defining_class === $base_fq_class_name) {
if (isset($extends[$base_fq_class_name][$atomic_type->param_name])) {
$extended_param = $extends[$base_fq_class_name][$atomic_type->param_name];

$atomic_type->as = $extended_param;
}
}
}

if ($atomic_type instanceof Type\Atomic\TArray
|| $atomic_type instanceof Type\Atomic\TIterable
|| $atomic_type instanceof Type\Atomic\TGenericObject
@@ -2595,6 +2595,27 @@ class CollectionChild extends Collection {
'$dogs' => 'CollectionChild<mixed, Dog>'
]
],
'extendsClassWithClassStringProperty' => [
'<?php
class Some {}
/** @template T of object */
abstract class Y {
/** @var class-string<T> */
protected $c;
}
/**
* @template T of Some
* @extends Y<Some>
*/
class Z extends Y {
/** @param class-string<T> $c */
public function __construct(string $c) {
$this->c = $c;
}
}'
],
];
}

0 comments on commit 72f3c30

Please sign in to comment.
You can’t perform that action at this time.