Skip to content

Wrong let expression parsing #7741

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

Open
auduchinok opened this issue Oct 18, 2019 · 6 comments
Open

Wrong let expression parsing #7741

auduchinok opened this issue Oct 18, 2019 · 6 comments
Assignees
Labels
Area-Compiler-Syntax lexfilter, indentation and parsing Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone

Comments

@auduchinok
Copy link
Member

auduchinok commented Oct 18, 2019

The contents of do in the following code should be parsed as a sequence of let expression and x, but it's parsed as let expression in sequence of the sum and x.

do
    let x = 1 in x + 1
    x

In addition to the unexpected tree form it also creates a wrong scope for x.

Screenshot 2019-10-17 at 14 35 50

AST viewer

@abelbraaksma
Copy link
Contributor

abelbraaksma commented Jul 23, 2020

Wait, doesn't in introduce scope? Shouldn't the last line x be out of scope for x?

(I admit I'm not sure of this, I use the in syntax rarely)

@auduchinok
Copy link
Member Author

@abelbraaksma It does, and its scope should be x + 1 here.

@abelbraaksma
Copy link
Contributor

abelbraaksma commented Jul 23, 2020

Edit, I may misunderstand the scoping here, as this seems to work properly well, it works, not sure of "properly":

let _ =
    let x = 1 in x + 2
    x  // in scope?

And if I take your code and paste it in VS, it correctly seems to say for each line that you're returning a value when you should return unit. But it appears to get the line number wrong for the second error.

If I remove the in it still gets the line number wrong (maybe not related to this issue):
image

@auduchinok
Copy link
Member Author

I'd expect it to be parsed as:

do
    (let x = 1 in (x + 1));
    x

And the latter x would be unresolved.

@dsyme
Copy link
Contributor

dsyme commented Aug 25, 2020

This is a long-standing issue and I think there are various duplicates of it. I suspect the right approach here is to start raising warnings when this formulation is used

@dsyme dsyme added the Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. label Aug 25, 2020
@auduchinok
Copy link
Member Author

auduchinok commented Sep 1, 2020

@dsyme How bad would be changing the parsing rules here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-Syntax lexfilter, indentation and parsing Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Projects
Status: New
Development

No branches or pull requests

5 participants