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
How to do simple generics #5706
Comments
This is fine, it should work. |
@szepeviktor After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
PHP 8.0 (1 error)
==========
-11: Function bar() should return T of int|string but returns T of int.
+ 8: Function bar() should return T of int|string but return statement is missing.
PHP 7.1 – 7.4 (2 errors)
==========
- 8: Function bar() uses native union types but they're supported only on PHP 8.0 and later.
-11: Function bar() should return T of int|string but returns T of int.
+ 8: Function bar() should return T of int|string but return statement is missing.
+ 8: Function bar() uses native union types but they're supported only on PHP 8.0 and later. Full reportPHP 8.0 (1 error)
PHP 7.1 – 7.4 (2 errors)
|
@ondrejmirtes The last commit made PHPStan miss the return statement. |
@szepeviktor After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.0 (1 error)
+PHP 8.0 (3 errors)
==========
+ 8: PHPDoc tag @param for parameter $key with type T of int|string is not subtype of native type int|string.
+ 8: PHPDoc tag @return with type T of int|string is not subtype of native type int|string.
11: Function bar() should return T of int|string but returns T of int.
-PHP 7.1 – 7.4 (2 errors)
+PHP 7.1 – 7.4 (4 errors)
==========
8: Function bar() uses native union types but they're supported only on PHP 8.0 and later.
+ 8: PHPDoc tag @param for parameter $key with type T of int|string is not subtype of native type int|string.
+ 8: PHPDoc tag @return with type T of int|string is not subtype of native type int|string.
11: Function bar() should return T of int|string but returns T of int. Full reportPHP 8.0 (3 errors)
PHP 7.1 – 7.4 (4 errors)
|
@arnaud-lb Oops, we broke it! |
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.0 – 8.1 (3 errors)
+PHP 8.0 – 8.1 (1 error)
==========
- 8: PHPDoc tag @param for parameter $key with type T of int|string is not subtype of native type int|string.
- 8: PHPDoc tag @return with type T of int|string is not subtype of native type int|string.
11: Function bar() should return T of int|string but returns T of int.
-PHP 7.1 – 7.4 (4 errors)
+PHP 7.1 – 7.4 (2 errors)
==========
8: Function bar() uses native union types but they're supported only on PHP 8.0 and later.
- 8: PHPDoc tag @param for parameter $key with type T of int|string is not subtype of native type int|string.
- 8: PHPDoc tag @return with type T of int|string is not subtype of native type int|string.
11: Function bar() should return T of int|string but returns T of int. Full reportPHP 8.0 – 8.1 (1 error)
PHP 7.1 – 7.4 (2 errors)
|
@szepeviktor After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.0 (1 error)
+PHP 8.0
==========
-11: Function bar() should return T of int|string but returns T of int.
+No errors
-PHP 7.1 – 7.4 (2 errors)
+PHP 7.1 – 7.4 (1 error)
==========
- 8: Function bar() uses native union types but they're supported only on PHP 8.0 and later.
-11: Function bar() should return T of int|string but returns T of int.
+ 8: Function bar() uses native union types but they're supported only on PHP 8.0 and later. Full reportPHP 8.0No errors PHP 7.1 – 7.4 (1 error)
|
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.0 – 8.1 (3 errors)
+PHP 8.0 – 8.1
==========
- 8: PHPDoc tag @param for parameter $key with type T of int|string is not subtype of native type int|string.
- 8: PHPDoc tag @return with type T of int|string is not subtype of native type int|string.
-11: Function bar() should return T of int|string but returns T of int.
+No errors
-PHP 7.1 – 7.4 (4 errors)
+PHP 7.1 – 7.4 (1 error)
==========
- 8: Function bar() uses native union types but they're supported only on PHP 8.0 and later.
- 8: PHPDoc tag @param for parameter $key with type T of int|string is not subtype of native type int|string.
- 8: PHPDoc tag @return with type T of int|string is not subtype of native type int|string.
-11: Function bar() should return T of int|string but returns T of int.
+ 8: Function bar() uses native union types but they're supported only on PHP 8.0 and later. Full reportPHP 8.0 – 8.1No errors PHP 7.1 – 7.4 (1 error)
|
Thank you. |
The PHPStan t-shirt has arrived here 😃 |
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
There is a function that receives a parameter of
string|int
and returns string or integer.Code snippet that reproduces the problem
https://phpstan.org/r/984d90d3-9515-4250-8613-cfc69b719abf
Expected output
No error.
Please help me achieve this.
Thank you.
The text was updated successfully, but these errors were encountered: