-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bleeding edge: stricter ++/-- operator check
- Loading branch information
1 parent
04f8636
commit a1e697b
Showing
6 changed files
with
266 additions
and
15 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
43 changes: 43 additions & 0 deletions
43
tests/PHPStan/Rules/Operators/data/invalid-inc-dec-mixed.php
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,43 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace InvalidIncDecMixed; | ||
|
||
/** | ||
* @template T | ||
* @param T $a | ||
*/ | ||
function genericMixed(mixed $a): void | ||
{ | ||
$b = $a; | ||
var_dump(++$b); | ||
$b = $a; | ||
var_dump($b++); | ||
$b = $a; | ||
var_dump(--$b); | ||
$b = $a; | ||
var_dump($b--); | ||
} | ||
|
||
function explicitMixed(mixed $a): void | ||
{ | ||
$b = $a; | ||
var_dump(++$b); | ||
$b = $a; | ||
var_dump($b++); | ||
$b = $a; | ||
var_dump(--$b); | ||
$b = $a; | ||
var_dump($b--); | ||
} | ||
|
||
function implicitMixed($a): void | ||
{ | ||
$b = $a; | ||
var_dump(++$b); | ||
$b = $a; | ||
var_dump($b++); | ||
$b = $a; | ||
var_dump(--$b); | ||
$b = $a; | ||
var_dump($b--); | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/PHPStan/Rules/Operators/data/invalid-inc-dec-union.php
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,32 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace InvalidIncDecUnion; | ||
|
||
/** | ||
* @param __benevolent<scalar|null|array|object> $benevolentUnion | ||
* @param string|int|float|bool|null $okUnion | ||
* @param scalar|null|array|object $union | ||
* @param __benevolent<array|object> $badBenevolentUnion | ||
*/ | ||
function foo($benevolentUnion, $okUnion, $union, $badBenevolentUnion): void | ||
{ | ||
$a = $benevolentUnion; | ||
$a++; | ||
$a = $benevolentUnion; | ||
--$a; | ||
|
||
$a = $okUnion; | ||
$a++; | ||
$a = $okUnion; | ||
--$a; | ||
|
||
$a = $union; | ||
$a++; | ||
$a = $union; | ||
--$a; | ||
|
||
$a = $badBenevolentUnion; | ||
$a++; | ||
$a = $badBenevolentUnion; | ||
--$a; | ||
} |
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