-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not add null to a template type for a default parameter value null
- Loading branch information
1 parent
2a0dccb
commit 7a66cb6
Showing
3 changed files
with
51 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Bug6584; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
public function doFoo(int $int, ?int $intOrNull) | ||
{ | ||
assertType('int', $this->same($int)); | ||
assertType('int', $this->sameWithDefault($int)); | ||
|
||
assertType('int|null', $this->same($intOrNull)); | ||
assertType('int|null', $this->sameWithDefault($intOrNull)); | ||
|
||
assertType('null', $this->same(null)); | ||
assertType('null', $this->sameWithDefault(null)); | ||
assertType('null', $this->sameWithDefault()); | ||
} | ||
|
||
|
||
/** | ||
* @template T | ||
* @param T $t | ||
* @return T | ||
*/ | ||
function same($t) { | ||
assertType('T (method Bug6584\Foo::same(), argument)', $t); | ||
return $t; | ||
} | ||
|
||
/** | ||
* @template T | ||
* @param T $t | ||
* @return T | ||
*/ | ||
function sameWithDefault($t = null) { | ||
assertType('T (method Bug6584\Foo::sameWithDefault(), argument)', $t); | ||
return $t; | ||
} | ||
|
||
} |