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
Generics restricted to array types are reporting errors #3384
Comments
@stof After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
4: PHPDoc tag @template T for class HelloWorld with bound type array<bool|float|int|string|null> is not supported.
9: Method HelloWorld::sayHello() has parameter $d with no value type specified in iterable type array.
- 9: PHPDoc tag @param for parameter $d with type T is not subtype of native type array.
-25: Parameter #1 $d of method HelloWorld<array<string, bool|string>>::sayHello() expects array('a' => string, 'b' => bool), array('a' => string, 'b' => DateTime) given.
+ 9: PHPDoc tag @param for parameter $d with type T is not subtype of native type array. Full report
|
This now kept only the errors I considered false positives, removing the one I considered OK... |
@stof After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
- 4: PHPDoc tag @template T for class HelloWorld with bound type array<bool|float|int|string|null> is not supported.
- 9: Method HelloWorld::sayHello() has parameter $d with no value type specified in iterable type array.
- 9: PHPDoc tag @param for parameter $d with type T is not subtype of native type array.
+ 4: PHPDoc tag @template T for class HelloWorld with bound type null is not supported.
25: Parameter #1 $d of method HelloWorld<array<string, bool|string>>::sayHello() expects array('a' => string, 'b' => bool), array('a' => string, 'b' => DateTime) given. Full report
|
@ondrejmirtes any reason to forbid |
@stof No reason, just that someone needs to step up and implement I believe it's really straightforward. |
@stof After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
- 4: PHPDoc tag @template T for class HelloWorld with bound type array<bool|float|int|string|null> is not supported.
- 9: Method HelloWorld::sayHello() has parameter $d with no value type specified in iterable type array.
- 9: PHPDoc tag @param for parameter $d with type T is not subtype of native type array.
-25: Parameter #1 $d of method HelloWorld<array<string, bool|string>>::sayHello() expects array('a' => string, 'b' => bool), array('a' => string, 'b' => DateTime) given.
+ 4: PHPDoc tag @template T for class HelloWorld with bound type null is not supported.
+25: Parameter #1 $d of method HelloWorld<array<string, bool|string>>::sayHello() expects array{a: string, b: bool}, array{a: string, b: DateTime} given. Full report
|
Solved the nullable union bound: phpstan/phpstan-src@1d8b2eb |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
I'd like to use a generic class, where the generic type is always an array of scalars, but the exact shape can be configured when using it. The typechecker already handles this fine for code using the class, but it reports errors in the class definition, for the
@template
annotation and for the@param
annotation.Code snippet that reproduces the problem
https://phpstan.org/r/e5cb3813-71b9-42b2-8e66-bcb65c8d2bcd
Expected output
Only the error at line 25 should be reported.
The text was updated successfully, but these errors were encountered: