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 --indent:3 can inject syntax errors #20078

Open
FredTheDino opened this issue Jul 23, 2022 · 0 comments
Open

nimpretty --indent:3 can inject syntax errors #20078

FredTheDino opened this issue Jul 23, 2022 · 0 comments
Assignees

Comments

@FredTheDino
Copy link

I was casually trying out Nim-lang and playing with nimpretty. Ofcourse I decided to mess with a flag called "indent", and nimpretty doesn't seem to handle this.

I don't really have the time to do a full bisect, I just installed it and played around. Felt it was better to report this than to ignore it.

Example run

 ~ :: nim r a.nim
Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: used config file '/etc/nim/config.nims' [Conf]
Hint: gc: refc; opt: none (DEBUG BUILD, `-d:release` generates faster code)
9905 lines; 0.010s; 8.645MiB peakmem; proj: /home/ed/a.nim; out: /home/ed/.cache/nim/a_d/a_5220365807561D8E69F6B4EBF89A3C6B14B8A8F3 [SuccessX]
Hint: /home/ed/.cache/nim/a_d/a_5220365807561D8E69F6B4EBF89A3C6B14B8A8F3  [Exec]
 ~ :: nimpretty a.nim --indent:10
 ~ :: nim r a.nim
Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: used config file '/etc/nim/config.nims' [Conf]
.........................................................
/home/ed/a.nim(5, 5) Error: invalid indentation

Example

a.nim before

proc x() =
  let
    x = if true: 1
        else: 0
    error = "abc"
  echo x

a.nim after nimpretty --indent:3

proc x() =
   let
      x = if true: 1
        else: 0
    error = "abc"
   echo x

This happens for indent:3 and indent:10. I haven't tested more, I suspect there are some assumptions in the formatter.

Expected Output

proc x() =
   let
      x = if true: 1
          else: 0
      error = "abc"
   echo x

Possible Solution

  • Remove the --indent flag, it looks like you
  • Fix the implicit assumption in the formatter for 2 spaces as indentation

Additional Information

nim version

Nim Compiler Version 1.6.6 [Linux: amd64]
Compiled at 2022-05-22
Copyright (c) 2006-2021 by Andreas Rumpf

active boot switches: -d:release

nimpretty version

0.2

Disclaimer

Haven't tested with head - nimpretty doesn't seem to have been touched in some time so I saved myself some time there. <3

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

4 participants