Skip to content

parsing of braceless for-comprehensions: unify error message for unintended code in various edge cases #11622

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

Closed
unkarjedy opened this issue Mar 5, 2021 · 3 comments

Comments

@unkarjedy
Copy link
Contributor

Compiler version

3.0.0-RC1

Minimized code

@main
def Main23() = {
    for x <- 0 to 1;
    x <- 0 to 1;
    do println(1)
  
    for 
        x <- 0 to 1
    y <- 0 to 1
    do println(2)
    
    for 
    x <- 0 to 1
  y <- 0 to 1
    do println(3)
}

Output

Note that compilation error "yield or do expected" is only shown for the 2nd for and not for the 1st and 3rd

Expectation

An error should be reported in all 3 cases or in none

image

@odersky
Copy link
Contributor

odersky commented Mar 5, 2021

That's because (1) or (3) don't see an indented region.

@odersky odersky closed this as completed Mar 5, 2021
@unkarjedy
Copy link
Contributor Author

Still looks awkward that this code is accepted by the compiler:
image
while the example with indented first enumerator is not.

Taking into account that braceless for-expressions require do/yield keyword maybe it's worth not treating indented region inside enumerators at all?

@bishabosha
Copy link
Member

bishabosha commented Mar 5, 2021

I refer to this comment chain - where indentation is not checked when the context it appears in is unambiguous: #8659 (review)

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

No branches or pull requests

3 participants