dawnbeen / c_formatter_42

C language formatter for 42 norminette
GNU General Public License v3.0
165 stars 17 forks source link

IndexError: list index out of range #48

Closed keit0728 closed 1 year ago

keit0728 commented 1 year ago

The following error occurs when using c_formatter_42. (Running from the console of VS code) It seems that #46 is not resolved.

Traceback (most recent call last):
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/keit/Library/Python/3.9/lib/python/site-packages/c_formatter_42/__main__.py", line 63, in <module>
    main()
  File "/Users/keit/Library/Python/3.9/lib/python/site-packages/c_formatter_42/__main__.py", line 43, in main
    print(run_all(content), end="")
  File "/Users/keit/Library/Python/3.9/lib/python/site-packages/c_formatter_42/run.py", line 30, in run_all
    content = preprocessor_directive(content)
  File "/Users/keit/Library/Python/3.9/lib/python/site-packages/c_formatter_42/formatters/preprocessor_directive.py", line 38, in preprocessor_directive
    lastline_index = idented[-1][0]
IndexError: list index out of range

The above error occurs in the code below.

int main(int argc, char*argv[]){
    return 0;
}

By the way, executing c_formatter_42 with the code below does not result in an error.

#define TRUE

int main(int argc, char*argv[]){
    return 0;
}
keyhr commented 1 year ago

Which version are you using? You can check it with pip show c-formatter-42.

keyhr commented 1 year ago

The error says that lastline_index = idented[-1][0] present on line 38, but it's on line 39 in the latest version. So I suppose that the c_formatter_42 you are using is v0.2.0 (previous version). Just try update it, and let me know if you get any errors.

cacharle commented 1 year ago

Just in case: python3 -m pip install -U c-formatter-42

keit0728 commented 1 year ago

@keyhr @cacharle After updating c_formatter_42 this error no longer occurs. Thank you for letting me know.