Skip to content

Only consider class-strings when resolving dependencies#239

Closed
rainbow-alex wants to merge 2 commits intophpstan:masterfrom
rainbow-alex:fix/only-resolve-class-strings
Closed

Only consider class-strings when resolving dependencies#239
rainbow-alex wants to merge 2 commits intophpstan:masterfrom
rainbow-alex:fix/only-resolve-class-strings

Conversation

@rainbow-alex
Copy link
Copy Markdown
Contributor

@rainbow-alex rainbow-alex commented Jun 10, 2020

@ondrejmirtes here is the change you suggested in #236. Tests seemed to be ok when I ran them locally with #238 included.

} elseif ($node instanceof Array_) {
} elseif (
$node instanceof Array_
&& $this->considerArrayForCallableTest($node)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure about this check or the implementation. Feels hacky to start excluding specific syntax at this point, no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should exclude String_ instead of just allowing ::class. This will also exclude examples like [$this, 'foo']. But I'm fine with this hack as long as it serves it purpose.

Copy link
Copy Markdown
Contributor Author

@rainbow-alex rainbow-alex Jun 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ondrejmirtes I was implementing your suggestion and I don't think it will fix the issue in our case, since there's the indirection via self::.

class Foobar
{
    self::FOO = 'foo';
    self::FOO = 'bar';
    self::FOOBAR = [self::FOO, self::BAR];
}

The only way to fix it by looking at the AST that I can see is to only allow ::class, which I agree is too strict.

edit: tested it and it doesn't fix the issue for us :(

@ondrejmirtes
Copy link
Copy Markdown
Member

Just tried something: b537b97

Please test phpstan/phpstan dev-master in 10-15 minutes. Thank you.

@rainbow-alex
Copy link
Copy Markdown
Contributor Author

I tried it and I no longer get any errors on master. Strangely enough if I comment out your fix I am not getting errors either. I'll try to look into this in depth later today.

@rainbow-alex
Copy link
Copy Markdown
Contributor Author

@ondrejmirtes When I create a minimal case I can confirm that your change fixes the issue. I suspect I am not seeing errors on master without your change because something caused the order of files to change again. But as far as I can see the fix is good! Thank you!

@rainbow-alex rainbow-alex deleted the fix/only-resolve-class-strings branch June 15, 2020 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants