mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Merge pull request #7872 from hirokinoue/float-template-arithmetics-4.x
don't emit issues when doing arithmetics on float templates
This commit is contained in:
commit
2724c1dba9
@ -445,20 +445,26 @@ class ArithmeticOpAnalyzer
|
||||
}
|
||||
|
||||
if ($left_type_part instanceof TTemplateParam || $right_type_part instanceof TTemplateParam) {
|
||||
if ($left_type_part instanceof TTemplateParam && !$left_type_part->as->isInt()) {
|
||||
if ($left_type_part instanceof TTemplateParam
|
||||
&& !$left_type_part->as->isInt()
|
||||
&& !$left_type_part->as->isFloat()
|
||||
) {
|
||||
if ($statements_source && IssueBuffer::accepts(
|
||||
new MixedOperand(
|
||||
'Left operand cannot be a non-int template',
|
||||
'Left operand cannot be a non-numeric template',
|
||||
new CodeLocation($statements_source, $left)
|
||||
),
|
||||
$statements_source->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
} elseif ($right_type_part instanceof TTemplateParam && !$right_type_part->as->isInt()) {
|
||||
} elseif ($right_type_part instanceof TTemplateParam
|
||||
&& !$right_type_part->as->isInt()
|
||||
&& !$right_type_part->as->isFloat()
|
||||
) {
|
||||
if ($statements_source && IssueBuffer::accepts(
|
||||
new MixedOperand(
|
||||
'Right operand cannot be a non-int template',
|
||||
'Right operand cannot be a non-numeric template',
|
||||
new CodeLocation($statements_source, $right)
|
||||
),
|
||||
$statements_source->getSuppressedIssues()
|
||||
|
@ -1603,6 +1603,22 @@ class FunctionTemplateTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'dontScreamForArithmeticsOnFloatTemplates' => [
|
||||
'<?php
|
||||
|
||||
/**
|
||||
* @template T of ?float
|
||||
* @param T $p
|
||||
* @return (T is null ? null : float)
|
||||
*/
|
||||
function foo(?float $p): ?float
|
||||
{
|
||||
if ($p === null) {
|
||||
return null;
|
||||
}
|
||||
return $p - 1;
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user