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

Property with declared type 'numeric' cannot be assigned type 'string(0)' #4154

Closed
vudaltsov opened this issue Sep 7, 2020 · 4 comments
Closed
Labels

Comments

@vudaltsov
Copy link
Contributor

https://psalm.dev/r/d6e5661e12

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/d6e5661e12
<?php

final class Request
{
    /**
     * @psalm-var numeric
     */
    public $index = '0';
    
    /**
     * @psalm-var numeric
     */
    public $index = 0;
    
    /**
     * @psalm-var numeric
     */
    public $index = 0.5;
}
Psalm output (using commit 8737abf):

ERROR: InvalidPropertyAssignmentValue - 8:21 - $this->index with declared type 'numeric' cannot be assigned type 'string(0)'

@weirdan
Copy link
Collaborator

weirdan commented Sep 7, 2020

Also it makes sense to flag duplicate properties.

@weirdan
Copy link
Collaborator

weirdan commented Sep 7, 2020

Reproduced without duplicates: https://psalm.dev/r/f1094923dd

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/f1094923dd
<?php

final class Request
{
    /**
     * @psalm-var numeric
     */
    public $index = '0';
}
Psalm output (using commit fe4af8f):

ERROR: InvalidPropertyAssignmentValue - 8:21 - $this->index with declared type 'numeric' cannot be assigned type 'string(0)'

@weirdan weirdan added the bug label Sep 7, 2020
@muglug muglug closed this as completed in 29efab5 Sep 8, 2020
danog pushed a commit to danog/psalm that referenced this issue Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants