-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variadic parameters in PHP8 can have int|string key #725
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,11 @@ public function dataFileAsserts(): iterable | |
yield from $this->gatherAssertTypes(__DIR__ . '/data/catch-without-variable.php'); | ||
} | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/mixed-typehint.php'); | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-2600.php'); | ||
if (PHP_VERSION_ID >= 80000) { | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-2600-php8.php'); | ||
} else { | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-2600.php'); | ||
} | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/array-typehint-without-null-in-phpdoc.php'); | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/override-root-scope-variable.php'); | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/bitwise-not.php'); | ||
|
@@ -427,7 +431,11 @@ public function dataFileAsserts(): iterable | |
|
||
if (self::$useStaticReflectionProvider || PHP_VERSION_ID >= 70400) { | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/arrow-function-types.php'); | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4902.php'); | ||
if (PHP_VERSION_ID >= 80000) { | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4902-php8.php'); | ||
} else { | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4902.php'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why it's no longer tested on PHP 8+? If there are different asserts, please create There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
} | ||
} | ||
|
||
yield from $this->gatherAssertTypes(__DIR__ . '/data/closure-types.php'); | ||
|
@@ -508,6 +516,10 @@ public function dataFileAsserts(): iterable | |
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4741.php'); | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/more-type-strings.php'); | ||
|
||
if (PHP_VERSION_ID >= 80000) { | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/variadic-parameter-php8.php'); | ||
} | ||
|
||
yield from $this->gatherAssertTypes(__DIR__ . '/data/eval-implicit-throw.php'); | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5628.php'); | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5501.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,88 @@ | ||
<?php | ||
|
||
namespace Bug2600; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
/** | ||
* @param mixed ...$x | ||
*/ | ||
public function doFoo($x = null) { | ||
$args = func_get_args(); | ||
assertType('mixed', $x); | ||
assertType('array', $args); | ||
} | ||
|
||
/** | ||
* @param mixed ...$x | ||
*/ | ||
public function doBar($x = null) { | ||
assertType('mixed', $x); | ||
} | ||
|
||
/** | ||
* @param mixed $x | ||
*/ | ||
public function doBaz(...$x) { | ||
assertType('array<int|string, mixed>', $x); | ||
} | ||
|
||
/** | ||
* @param mixed ...$x | ||
*/ | ||
public function doLorem(...$x) { | ||
assertType('array<int|string, mixed>', $x); | ||
} | ||
|
||
public function doIpsum($x = null) { | ||
$args = func_get_args(); | ||
assertType('mixed', $x); | ||
assertType('array', $args); | ||
} | ||
} | ||
|
||
class Bar | ||
{ | ||
/** | ||
* @param string ...$x | ||
*/ | ||
public function doFoo($x = null) { | ||
$args = func_get_args(); | ||
assertType('string|null', $x); | ||
assertType('array', $args); | ||
} | ||
|
||
/** | ||
* @param string ...$x | ||
*/ | ||
public function doBar($x = null) { | ||
assertType('string|null', $x); | ||
} | ||
|
||
/** | ||
* @param string $x | ||
*/ | ||
public function doBaz(...$x) { | ||
assertType('array<int|string, string>', $x); | ||
} | ||
|
||
/** | ||
* @param string ...$x | ||
*/ | ||
public function doLorem(...$x) { | ||
assertType('array<int|string, string>', $x); | ||
} | ||
} | ||
|
||
function foo($x, string ...$y): void | ||
{ | ||
assertType('mixed', $x); | ||
assertType('array<int|string, string>', $y); | ||
} | ||
|
||
function ($x, string ...$y): void { | ||
assertType('mixed', $x); | ||
assertType('array<int|string, string>', $y); | ||
}; |
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,53 @@ | ||
<?php // lint >= 7.4 | ||
|
||
namespace Bug4902; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
/** | ||
* @template T-wrapper | ||
*/ | ||
class Wrapper { | ||
/** @var T-wrapper */ | ||
public $value; | ||
|
||
/** | ||
* @param T-wrapper $value | ||
*/ | ||
public function __construct($value) { | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @template T-unwrap | ||
* @param Wrapper<T-unwrap> $wrapper | ||
* @return T-unwrap | ||
*/ | ||
function unwrap(Wrapper $wrapper) { | ||
return $wrapper->value; | ||
} | ||
|
||
/** | ||
* @template T-wrap | ||
* @param T-wrap $value | ||
* | ||
* @return Wrapper<T-wrap> | ||
*/ | ||
function wrap($value): Wrapper | ||
{ | ||
return new Wrapper($value); | ||
} | ||
|
||
|
||
/** | ||
* @template T-all | ||
* @param Wrapper<T-all> ...$wrappers | ||
*/ | ||
function unwrapAllAndWrapAgain(Wrapper ...$wrappers): void { | ||
assertType('array<int|string, T-all (method Bug4902\Wrapper::unwrapAllAndWrapAgain(), argument)>', array_map(function (Wrapper $item) { | ||
return $this->unwrap($item); | ||
}, $wrappers)); | ||
assertType('array<int|string, T-all (method Bug4902\Wrapper::unwrapAllAndWrapAgain(), argument)>', array_map(fn (Wrapper $item) => $this->unwrap($item), $wrappers)); | ||
} | ||
|
||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace VariadicParameterPHP8; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function foo(...$args) | ||
{ | ||
assertType('array<int|string, mixed>', $args); | ||
assertType('mixed', $args['foo']); | ||
assertType('mixed', $args['bar']); | ||
} | ||
|
||
function bar(string ...$args) | ||
{ | ||
assertType('array<int|string, string>', $args); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it's no longer tested on PHP 8+? If there are different asserts, please create
bug-2600-php8.php
for that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.