-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix how well conditional types play with pre-existing
@param-out
va…
…riable after assignment
- Loading branch information
1 parent
2b97628
commit 5892e8d
Showing
3 changed files
with
39 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Bug11580; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
final class HelloWorld | ||
{ | ||
public function bad(string $in): void | ||
{ | ||
$matches = []; | ||
if (preg_match('~^/xxx/([\w\-]+)/?([\w\-]+)?/?$~', $in, $matches)) { | ||
assertType('array{0: string, 1: non-empty-string, 2?: non-empty-string}', $matches); | ||
} | ||
} | ||
|
||
public function bad2(string $in): void | ||
{ | ||
$matches = []; | ||
$result = preg_match('~^/xxx/([\w\-]+)/?([\w\-]+)?/?$~', $in, $matches); | ||
if ($result) { | ||
assertType('array{0: string, 1: non-empty-string, 2?: non-empty-string}', $matches); | ||
} | ||
} | ||
|
||
public function bad3(string $in): void | ||
{ | ||
$result = preg_match('~^/xxx/([\w\-]+)/?([\w\-]+)?/?$~', $in, $matches); | ||
assertType('array{0?: string, 1?: non-empty-string, 2?: non-empty-string}', $matches); | ||
if ($result) { | ||
assertType('array{0: string, 1: non-empty-string, 2?: non-empty-string}', $matches); | ||
} | ||
} | ||
|
||
} |
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