mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 12:55:26 +01:00
Merge pull request #6478 from whsv26/bugfix/trait-template-invalid-arg
Fix invalid argument bug in generic trait context
This commit is contained in:
commit
55fd9c6713
@ -92,6 +92,19 @@ class ObjectComparator
|
||||
continue 3;
|
||||
}
|
||||
}
|
||||
} elseif ($intersection_input_type instanceof TTemplateParam) {
|
||||
$container_param = $intersection_container_type->param_name;
|
||||
$container_class = $intersection_container_type->defining_class;
|
||||
$input_class_like = $codebase->classlikes
|
||||
->getStorageFor($intersection_input_type->defining_class);
|
||||
|
||||
if ($codebase->classlikes->traitExists($container_class)
|
||||
&& !\is_null($input_class_like)
|
||||
&& isset(
|
||||
$input_class_like->template_extended_params[$container_class][$container_param]
|
||||
)) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -474,6 +474,43 @@ class TraitTemplateTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'templateExtendedGenericTrait' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template F
|
||||
*/
|
||||
trait Foo {
|
||||
/**
|
||||
* @param callable(F): int $callback
|
||||
*/
|
||||
public function bar(callable $callback): int {
|
||||
return $callback($this->get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @template B
|
||||
*/
|
||||
class Bar {
|
||||
|
||||
/**
|
||||
* @use Foo<B>
|
||||
*/
|
||||
use Foo;
|
||||
|
||||
/**
|
||||
* @param B $value
|
||||
*/
|
||||
public function __construct(public mixed $value) { }
|
||||
|
||||
/**
|
||||
* @return B
|
||||
*/
|
||||
public function get() {
|
||||
return $this->value;
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user