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

nimpretty generates wrong code with parenthesized expressions #18498

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

nimpretty generates wrong code with parenthesized expressions #18498

hamidb80 opened this issue Jul 15, 2021 · 2 comments

Comments

@hamidb80
Copy link
Contributor

I really can't explain what's going on, just see the examples

Example 1

no changes, everything is OK

let temp =
  if true:
    1
  else:
    discard nil
    2

=== nim pretty ===>>

let temp =
  if true:
    1
  else:
    discard nil
    2

Example 2

things getting wierd by parentheses

let temp = (
  if true:
    1
  else:
    discard nil
    2
)

=== nim pretty ===>

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

notice: the code still compiles

Example 3

just a proc def top of the par expression

proc myProc =
  discard

let temp = (
  if true:
    1
  else:
    discard nil
    2
)

=== nim pretty ===>

proc myProc =
  discard

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

error on compile:

Error: expression '1' is of type 'int literal(1)' and has to be used (or 
discarded)

Example 4

2 var defs, one with pars:

let temp = (
  if true:
    1
  else:
    discard nil
    2
)

let temp2 =
  if true:
    1
  else:
    discard nil
    2

=== nim pretty ===>

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

let temp2 =
    if true: # <------------ indent
    1
  else:
    discard nil
    2

notice: compiles successfully

Example 5

2 var defs with proc def top of them one with pars:

proc myProc =
  discard

let temp = (
  if true:
    1
  else:
    discard nil
    2
)

let temp2 =
  if true:
    1
  else:
    discard nil
    2

=== nim pretty ===>

proc myProc =
  discard

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

let temp2 =
  if true:
    1
  else:
    discard nil
    2

notice: compile error same as Example 3

Additional Information

$ nim -v
Nim Compiler Version 1.5.1 [Windows: amd64]
Compiled at 2021-06-20
Copyright (c) 2006-2021 by Andreas Rumpf
@timotheecour timotheecour changed the title nimpretty generates wrong code nimpretty generates wrong code with parenthesized expressions Jul 15, 2021
@timotheecour
Copy link
Member

notice: the code still compiles

=> filed #18500

PR welcome to help with nimpretty

@hamidb80
Copy link
Contributor Author

hamidb80 commented Jul 3, 2023

no problem with Nim version 1.6.14
sorry that was a mistake

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