Skip to content

Commit 163dac1

Browse files
committed
fix(analyzer): skip binding to generic parameter when constraint is not satisfied
Signed-off-by: azjezz <[email protected]>
1 parent b2db038 commit 163dac1

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

crates/analyzer/src/invocation/template_inference.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,20 @@ fn infer_templates_from_input_and_container_types(
751751
continue;
752752
}
753753

754+
if !container_generic.constraint.has_template_types()
755+
&& !union_comparator::is_contained_by(
756+
context.codebase,
757+
&residual_input_type,
758+
&container_generic.constraint,
759+
false,
760+
false,
761+
false,
762+
&mut ComparisonResult::default(),
763+
)
764+
{
765+
continue;
766+
}
767+
754768
let mut has_violation = false;
755769

756770
if let Some(template_types) = template_result.template_types.get(template_parameter_name) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
final class Something
6+
{
7+
public string $name;
8+
9+
public function someMethod(): void
10+
{
11+
}
12+
}
13+
14+
$reflectionClass = new ReflectionClass(Something::class);
15+
$instance = $reflectionClass->newInstanceWithoutConstructor();
16+
$instance->name = 'test';
17+
$instance->someMethod();

crates/analyzer/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ test_case!(issue_689);
416416
test_case!(issue_690);
417417
test_case!(issue_701);
418418
test_case!(issue_706);
419+
test_case!(issue_709);
419420
test_case!(issue_710);
420421
test_case!(issue_708_part_1);
421422
test_case!(issue_708_part_2);

0 commit comments

Comments
 (0)