mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #4517 - track type contradiction issues in match expressions
This commit is contained in:
parent
3aaa1d8447
commit
e97a9c86eb
@ -106,10 +106,14 @@ class MatchAnalyzer
|
||||
new PhpParser\Node\Expr\Throw_(
|
||||
new PhpParser\Node\Expr\New_(
|
||||
new PhpParser\Node\Name\FullyQualified(
|
||||
'UnhandledMatchError'
|
||||
)
|
||||
'UnhandledMatchError',
|
||||
$stmt->getAttributes()
|
||||
),
|
||||
[],
|
||||
$stmt->getAttributes()
|
||||
)
|
||||
)
|
||||
),
|
||||
$stmt->getAttributes()
|
||||
);
|
||||
}
|
||||
|
||||
@ -255,17 +259,28 @@ class MatchAnalyzer
|
||||
new PhpParser\Node\Name\FullyQualified(['in_array']),
|
||||
[
|
||||
new PhpParser\Node\Arg(
|
||||
$match_condition
|
||||
$match_condition,
|
||||
false,
|
||||
false,
|
||||
$attributes
|
||||
),
|
||||
new PhpParser\Node\Arg(
|
||||
new PhpParser\Node\Expr\Array_(
|
||||
$array_items
|
||||
)
|
||||
$array_items,
|
||||
$attributes
|
||||
),
|
||||
false,
|
||||
false,
|
||||
$attributes
|
||||
),
|
||||
new PhpParser\Node\Arg(
|
||||
new PhpParser\Node\Expr\ConstFetch(
|
||||
new PhpParser\Node\Name\FullyQualified(['true'])
|
||||
)
|
||||
new PhpParser\Node\Name\FullyQualified(['true']),
|
||||
$attributes
|
||||
),
|
||||
false,
|
||||
false,
|
||||
$attributes
|
||||
),
|
||||
],
|
||||
$attributes
|
||||
|
@ -72,3 +72,5 @@ class ReflectionUnionType extends ReflectionType {
|
||||
*/
|
||||
public function getTypes() {}
|
||||
}
|
||||
|
||||
class UnhandledMatchError extends Error {}
|
||||
|
@ -205,6 +205,18 @@ class MatchTest extends TestCase
|
||||
false,
|
||||
'8.0',
|
||||
],
|
||||
'matchTrueImpossible' => [
|
||||
'<?php
|
||||
$foo = new \stdClass();
|
||||
$a = match (true) {
|
||||
$foo instanceof \stdClass => 1,
|
||||
$foo instanceof \Exception => 1,
|
||||
};',
|
||||
'error_message' => 'TypeDoesNotContainType',
|
||||
[],
|
||||
false,
|
||||
'8.0',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user