-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Early termination for NeverType match expression
- Loading branch information
1 parent
c564943
commit 99951ac
Showing
16 changed files
with
156 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php declare(strict_types = 1); // lint >= 8.0 | ||
|
||
namespace Bug6251; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
function foo() | ||
{ | ||
$var = 1; | ||
if (rand(0, 1)) { | ||
match(1) { | ||
1 => throw new \Exception(), | ||
}; | ||
} else { | ||
$var = 2; | ||
} | ||
assertType('2', $var); | ||
} | ||
|
||
function bar($a): void | ||
{ | ||
$var = 1; | ||
if (rand(0, 1)) { | ||
match($a) { | ||
'a' => throw new \Error(), | ||
default => throw new \Exception(), | ||
}; | ||
} else { | ||
$var = 2; | ||
} | ||
assertType('2', $var); | ||
} | ||
|
||
function baz($a): void | ||
{ | ||
$var = 1; | ||
if (rand(0, 1)) { | ||
match($a) { | ||
'a' => throw new \Error(), | ||
// throws UnhandledMatchError if not handled | ||
}; | ||
} else { | ||
$var = 2; | ||
} | ||
assertType('2', $var); | ||
} | ||
|
||
function buz($a): void | ||
{ | ||
$var = 1; | ||
if (rand(0, 1)) { | ||
match($a) { | ||
'a' => throw new \Exception(), | ||
default => var_dump($a), | ||
}; | ||
} else { | ||
$var = 2; | ||
} | ||
assertType('1|2', $var); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php // lint >= 8.0 | ||
|
||
namespace ReturnTypes; | ||
|
||
/** | ||
* @return never | ||
*/ | ||
function alwaysThrow() { | ||
match(true) { | ||
true => throw new \Exception(), | ||
}; | ||
} | ||
|
||
/** | ||
* @return never | ||
*/ | ||
function alwaysThrow2() { | ||
match(rand(0, 1)) { | ||
0 => throw new \Exception(), | ||
}; | ||
} | ||
|
||
/** | ||
* @return never | ||
*/ | ||
function sometimesThrows() { | ||
match(rand(0, 1)) { | ||
0 => throw new \Exception(), | ||
default => 'test', | ||
}; | ||
} |