fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Wrong let expression parsing

Open auduchinok opened this issue 6 years ago • 6 comments

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

auduchinok avatar Oct 18 '19 10:10 auduchinok

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)

abelbraaksma avatar Jul 23 '20 17:07 abelbraaksma

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

auduchinok avatar Jul 23 '20 17:07 auduchinok

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

abelbraaksma avatar Jul 23 '20 17:07 abelbraaksma

I'd expect it to be parsed as:

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

And the latter x would be unresolved.

auduchinok avatar Jul 23 '20 17:07 auduchinok

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 avatar Aug 25 '20 15:08 dsyme

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

auduchinok avatar Sep 01 '20 11:09 auduchinok