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

parser accepts invalid indentation in parenthesized expression #18500

Open
timotheecour opened this issue Jul 15, 2021 · 2 comments
Open

parser accepts invalid indentation in parenthesized expression #18500

timotheecour opened this issue Jul 15, 2021 · 2 comments
Labels
Invalid Code Acceptance Everything related to compiler not complaining about invalid code Parser

Comments

@timotheecour
Copy link
Member

found in #18498

Example

let temp = (
  if true:
    1
else:  # <------ unindented
    discard nil
    2
)

Current Output

compiles

Expected Output

CT error because of indentation

Additional Information

1.5.1 12da32a

@timotheecour timotheecour added Parser Invalid Code Acceptance Everything related to compiler not complaining about invalid code labels Jul 15, 2021
@Clyybber
Copy link
Contributor

That is specific to if and when expressions and intentional.

let temp = if true:
    1
else:  # <------ unindented
    discard nil
    2

@timotheecour
Copy link
Member Author

timotheecour commented Jul 15, 2021

this doesn't make sense. there is no valid practical purpose to allow code like this:

when true:
  (
    if true:
      echo 1
elif true:
      echo 2
     else:
      echo 3
  )

and as you can see here, it breaks consistency, eg if you replace echo(2) by if true: echo(2) it stops working:

when true:
  (
    if true:
      echo 1
elif true:
  # echo(2) # works
  if true: echo(2) # fails
  )

instead of closing immediately, let others chime in at least for a few days

parenthesized should allow useful things like #8258, but not random code like above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invalid Code Acceptance Everything related to compiler not complaining about invalid code Parser
Projects
None yet
Development

No branches or pull requests

2 participants