1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Improve solution to #3964

This commit is contained in:
Matthew Brown 2020-08-16 13:03:30 -04:00
parent ec2178d14a
commit 5c20a5295e
5 changed files with 34 additions and 32 deletions

View File

@ -720,6 +720,8 @@ class UnionTemplateHandler
$generic_param,
$codebase
);
} else {
$intersection_type = $generic_param;
}
if ($intersection_type) {

View File

@ -1505,6 +1505,25 @@ class ArrayFunctionCallTest extends TestCase
'$array' => 'list<int>',
],
],
'closureParamConstraintsMet' => [
'<?php
class A {}
class B {}
$test = [new A(), new B()];
usort(
$test,
/**
* @param A|B $a
* @param A|B $b
*/
function($a, $b): int
{
return $a === $b ? 1 : -1;
}
);'
],
'specialCaseArrayFilterOnSingleEntry' => [
'<?php
/** @psalm-return list<int> */
@ -1862,6 +1881,18 @@ class ArrayFunctionCallTest extends TestCase
usort($list, fn(int $a, string $b): int => (int) ($a > $b));',
'error_message' => 'InvalidScalarArgument'
],
'usortInvalidComparison' => [
'<?php
$arr = [["one"], ["two"], ["three"]];
usort(
$arr,
function (string $a, string $b): int {
return strcmp($a, $b);
}
);',
'error_message' => 'InvalidArgument',
],
];
}
}

View File

@ -1596,18 +1596,6 @@ class FunctionCallTest extends TestCase
function sort() : void {}',
'error_message' => 'DuplicateFunction',
],
'usortInvalidComparison' => [
'<?php
$arr = [["one"], ["two"], ["three"]];
usort(
$arr,
function (string $a, string $b): int {
return strcmp($a, $b);
}
);',
'error_message' => 'InvalidArgument',
],
'functionCallOnMixed' => [
'<?php
/**

View File

@ -1337,25 +1337,6 @@ class FunctionTemplateTest extends TestCase
[],
'7.4'
],
'closureParamConstraintsMet' => [
'<?php
class A {}
class B {}
$test = [new A(), new B()];
usort(
$test,
/**
* @param A|B $a
* @param A|B $b
*/
function($a, $b): int
{
return $a === $b ? 1 : -1;
}
);'
],
];
}

View File

@ -80,7 +80,7 @@ class TestCase extends BaseTestCase
$this->project_analyzer->setPhpVersion('7.3');
$this->project_analyzer->setPhpVersion('7.4');
}
public function tearDown() : void