Skip to content
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

Incorrect type inference from result of array_map #1652

Closed
marcospassos opened this issue Nov 25, 2018 · 7 comments
Closed

Incorrect type inference from result of array_map #1652

marcospassos opened this issue Nov 25, 2018 · 7 comments
Labels
Milestone

Comments

@marcospassos
Copy link

Summary of a problem or a feature request

The type inference from the result of array_map seems wrong.

Code snippet that reproduces the problem

https://phpstan.org/r/b8dbc80d-ded7-42e4-9ed5-db6d8d795eb0

Expected output

No error.

@JanTvrdik
Copy link
Contributor

That's unrelated to array_map. https://phpstan.org/r/9b0361b9-b4f3-43b9-821a-7e5739e28f99

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Nov 27, 2018
@ondrejmirtes
Copy link
Member

Yeah, StaticResolvableType::resolveStatic needs to be called in more cases.

@phpstan-bot
Copy link
Contributor

@marcospassos PHPStan now reports different result with your code snippet:

@@ @@
-20: Parameter #1 ...$bars of function bar expects array<int, Bar>, array<int, static(Foo)> given.
+10: Unsafe usage of new static().
+17: Function bar() has no return typehint specified.
+20: Parameter #1 ...$bars of function bar expects Bar, static(Foo) given.
Full report
Line Error
10 Parameter #1 ...$bars of function bar expects Bar, static(Foo) given.
17 Parameter #1 ...$bars of function bar expects Bar, static(Foo) given.
20 Parameter #1 ...$bars of function bar expects Bar, static(Foo) given.

@phpstan-bot
Copy link
Contributor

@JanTvrdik PHPStan now reports different result with your code snippet:

@@ @@
+10: Unsafe usage of new static().
 23: Strict comparison using === between static(Foo) and 0 will always evaluate to false.
 24: Strict comparison using === between static(Foo) and 0 will always evaluate to false.
Full report
Line Error
10 Strict comparison using === between static(Foo) and 0 will always evaluate to false.
23 Strict comparison using === between static(Foo) and 0 will always evaluate to false.
24 Strict comparison using === between static(Foo) and 0 will always evaluate to false.

@phpstan-bot
Copy link
Contributor

@marcospassos After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-20: Parameter #1 ...$bars of function bar expects array<int, Bar>, array<int, static(Foo)> given.
+10: Unsafe usage of new static().
+17: Function bar() has no return typehint specified.
Full report
Line Error
10 Unsafe usage of new static().
17 Function bar() has no return typehint specified.

@phpstan-bot
Copy link
Contributor

@JanTvrdik After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-23: Strict comparison using === between static(Foo) and 0 will always evaluate to false.
-24: Strict comparison using === between static(Foo) and 0 will always evaluate to false.
+10: Unsafe usage of new static().
+23: Strict comparison using === between Foo and 0 will always evaluate to false.
+24: Strict comparison using === between Bar and 0 will always evaluate to false.
Full report
Line Error
10 Unsafe usage of new static().
23 Strict comparison using === between Foo and 0 will always evaluate to false.
24 Strict comparison using === between Bar and 0 will always evaluate to false.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants