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

Invalid error for float type check using 0 #1961

Closed
rimvislt opened this issue Mar 7, 2019 · 7 comments
Closed

Invalid error for float type check using 0 #1961

rimvislt opened this issue Mar 7, 2019 · 7 comments
Labels
Milestone

Comments

@rimvislt
Copy link

rimvislt commented Mar 7, 2019

Summary of a problem or a feature request

Using 0 as default parameter for float type argument gives error:
Default value of the parameter #1 xx of method nn is incompatible with type float.

Code snippet that reproduces the problem

public function test2(float $test2 = 0): void { //}
https://phpstan.org/r/83d22916-c7a8-4bc3-8d37-27b361326329

Expected output

No error

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Mar 7, 2019
@mpesari
Copy link

mpesari commented Mar 19, 2019

Just ran into this and wanted to share this case where it doesn't occur with a method coming from a trait. Maybe it's helpful.. or not..

https://phpstan.org/r/88fa77d4-6c83-4066-87d7-67e1c8762cb5

@ondrejmirtes
Copy link
Member

Traits in playground behave in a weird way. When running locally, both occurences are reported.

@dktapps
Copy link
Contributor

dktapps commented Jan 28, 2020

A generalized blacklist regex I use for this bug:
message: "#^Default value of the parameter \\#\\d+ \\$[A-Za-z\\d_]+ \\(\\-?\\d+\\) of method .+\\(\\) is incompatible with type float\\.$#"

Maybe someone else will find it useful.

@VincentLanglet
Copy link
Contributor

Why not using ?

public function test2(float $test2 = 0.0): void { //}

@dktapps
Copy link
Contributor

dktapps commented Apr 19, 2020

It can be done, but when there are hundreds of places in your code where an integer literal is used, it's not very appealing to change them all because of a small bug in a static analyser.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@a5beb06

@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 May 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants