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

Undefined variables in string interpolation are not being caught #5331

Closed
Ocramius opened this issue Mar 5, 2021 · 5 comments · Fixed by #5343
Closed

Undefined variables in string interpolation are not being caught #5331

Ocramius opened this issue Mar 5, 2021 · 5 comments · Fixed by #5343
Labels

Comments

@Ocramius
Copy link
Contributor

Ocramius commented Mar 5, 2021

Taken from the convo @ https://twitter.com/mattbrowndev/status/1367965245084491783 (sorry, I just happen to review too much code :| )

<?php

(function () : void {
    echo (fn(string $b) => "$b - $undefined")("hello");
})();

https://psalm.dev/r/d5662fa596

It should report $undefined as undefined, but it doesn't.

See https://3v4l.org/D8tJR for runtime verification.

@psalm-github-bot
Copy link

I found these snippets:

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

(function () : void {
    echo (fn(string $b) => "$b - $undefined")("hello");
})();
Psalm output (using commit 96e0743):

No issues!

@weirdan
Copy link
Collaborator

weirdan commented Mar 5, 2021

Simplified and added one more variation: https://psalm.dev/r/9520a78b52

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/9520a78b52
<?php
function a(): void {
    fn(): string => (string) $undefined;
}

function b(): void {
    fn(): string => "$undefined";   
}
Psalm output (using commit 96e0743):

No issues!

@weirdan weirdan added the bug label Mar 5, 2021
weirdan added a commit to weirdan/psalm that referenced this issue Mar 8, 2021
Previously Psalm would assume that any variable it sees in the arrow
function body is defined (and mixed, if it's not available in the outer
scope). This prevented undefined variable detection. Dropping that
assumption allows it to work.

Fixes vimeo#5331
muglug pushed a commit that referenced this issue Mar 11, 2021
Previously Psalm would assume that any variable it sees in the arrow
function body is defined (and mixed, if it's not available in the outer
scope). This prevented undefined variable detection. Dropping that
assumption allows it to work.

Fixes #5331
@Ocramius
Copy link
Contributor Author

Thanks, @muglug!

@orklah
Copy link
Collaborator

orklah commented Mar 11, 2021

And thanks @weirdan for the PR! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants