1
0
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:
orklah 2021-09-20 16:53:12 +02:00 committed by GitHub
commit 55fd9c6713
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 0 deletions

View File

@ -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;
}
}
}

View File

@ -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;
}
}'
],
];
}