mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Add back nuance to error messages for conflicting type bounds
This commit is contained in:
parent
be87bb7300
commit
a117c48bb2
@ -3838,23 +3838,74 @@ class CallAnalyzer
|
||||
if (isset($template_result->upper_bounds[$template_name][$defining_id])) {
|
||||
$upper_bound_type = $template_result->upper_bounds[$template_name][$defining_id][0];
|
||||
|
||||
$union_comparison_result = new \Psalm\Internal\Analyzer\TypeComparisonResult();
|
||||
|
||||
if (!TypeAnalyzer::isContainedBy(
|
||||
$statements_analyzer->getCodebase(),
|
||||
$upper_bound_type,
|
||||
$lower_bound_type
|
||||
$lower_bound_type,
|
||||
false,
|
||||
false,
|
||||
$union_comparison_result
|
||||
)) {
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidArgument(
|
||||
'Could not reconcile upper and lower bounds '
|
||||
. $upper_bound_type->getId() . ' and '
|
||||
. $lower_bound_type->getId() . ' for template param '
|
||||
. $template_name,
|
||||
$code_location,
|
||||
$function_id
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// continue
|
||||
if ($union_comparison_result->type_coerced) {
|
||||
if ($union_comparison_result->type_coerced_from_mixed) {
|
||||
if (IssueBuffer::accepts(
|
||||
new MixedArgumentTypeCoercion(
|
||||
'Could not reconcile upper and lower bounds '
|
||||
. $upper_bound_type->getId() . ' and '
|
||||
. $lower_bound_type->getId() . ' for template param '
|
||||
. $template_name,
|
||||
$code_location,
|
||||
$function_id
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// continue
|
||||
}
|
||||
} else {
|
||||
if (IssueBuffer::accepts(
|
||||
new ArgumentTypeCoercion(
|
||||
'Could not reconcile upper and lower bounds '
|
||||
. $upper_bound_type->getId() . ' and '
|
||||
. $lower_bound_type->getId() . ' for template param '
|
||||
. $template_name,
|
||||
$code_location,
|
||||
$function_id
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// continue
|
||||
}
|
||||
}
|
||||
} elseif ($union_comparison_result->scalar_type_match_found) {
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidScalarArgument(
|
||||
'Could not reconcile upper and lower bounds '
|
||||
. $upper_bound_type->getId() . ' and '
|
||||
. $lower_bound_type->getId() . ' for template param '
|
||||
. $template_name,
|
||||
$code_location,
|
||||
$function_id
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// continue
|
||||
}
|
||||
} else {
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidArgument(
|
||||
'Could not reconcile upper and lower bounds '
|
||||
. $upper_bound_type->getId() . ' and '
|
||||
. $lower_bound_type->getId() . ' for template param '
|
||||
. $template_name,
|
||||
$code_location,
|
||||
$function_id
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// continue
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1377,7 +1377,7 @@ class FunctionTemplateTest extends TestCase
|
||||
}
|
||||
|
||||
apply(function(int $_i) : void {}, "hello");',
|
||||
'error_message' => 'InvalidArgument',
|
||||
'error_message' => 'InvalidScalarArgument',
|
||||
],
|
||||
'bindFirstTemplatedClosureParameterTypeCoercion' => [
|
||||
'<?php
|
||||
@ -1396,7 +1396,7 @@ class FunctionTemplateTest extends TestCase
|
||||
class AChild extends A {}
|
||||
|
||||
apply(function(AChild $_i) : void {}, new A());',
|
||||
'error_message' => 'InvalidArgument',
|
||||
'error_message' => 'ArgumentTypeCoercion',
|
||||
],
|
||||
|
||||
'callableDoesNotReturnItself' => [
|
||||
@ -1418,7 +1418,7 @@ class FunctionTemplateTest extends TestCase
|
||||
function takesReturnTCallable(callable $s) {}
|
||||
|
||||
takesReturnTCallable($b);',
|
||||
'error_message' => 'InvalidArgument',
|
||||
'error_message' => 'InvalidScalarArgument',
|
||||
],
|
||||
'multipleArgConstraintWithMoreRestrictiveFirstArg' => [
|
||||
'<?php
|
||||
@ -1441,7 +1441,7 @@ class FunctionTemplateTest extends TestCase
|
||||
function(A $_a) : void {},
|
||||
new A()
|
||||
);',
|
||||
'error_message' => 'InvalidArgument',
|
||||
'error_message' => 'ArgumentTypeCoercion',
|
||||
],
|
||||
'multipleArgConstraintWithMoreRestrictiveSecondArg' => [
|
||||
'<?php
|
||||
@ -1464,7 +1464,7 @@ class FunctionTemplateTest extends TestCase
|
||||
function(AChild $_a) : void {},
|
||||
new A()
|
||||
);',
|
||||
'error_message' => 'InvalidArgument',
|
||||
'error_message' => 'ArgumentTypeCoercion',
|
||||
],
|
||||
'multipleArgConstraintWithLessRestrictiveThirdArg' => [
|
||||
'<?php
|
||||
@ -1487,7 +1487,7 @@ class FunctionTemplateTest extends TestCase
|
||||
function(AChild $_a) : void {},
|
||||
new A()
|
||||
);',
|
||||
'error_message' => 'InvalidArgument',
|
||||
'error_message' => 'ArgumentTypeCoercion',
|
||||
],
|
||||
'possiblyInvalidArgumentWithUnionFirstArg' => [
|
||||
'<?php
|
||||
|
Loading…
Reference in New Issue
Block a user