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

Compiler assertion error when assigning variable using error #3823

Closed
jasoncarr0 opened this issue Aug 11, 2021 · 3 comments · Fixed by #3980
Closed

Compiler assertion error when assigning variable using error #3823

jasoncarr0 opened this issue Aug 11, 2021 · 3 comments · Fixed by #3980
Labels
good first issue Good for newcomers

Comments

@jasoncarr0
Copy link
Contributor

jasoncarr0 commented Aug 11, 2021

This function body causes an assertion error in the compiler (version 0.42.0 in this case but I also see it in a slightly modified version of 0.45.0). I couldn't find another issue for this yet but it's not easy to search for.

Found this on a hunch/check while looking at the error-flag code, hoping to fix with possible other changes

     let x: String = (error)

This results in:

[removed]/ponyc/src/libponyc/pass/expr.c:652: pass_expr: Assertion `errors_get_count(options->check.errors) > 0` failed.

Backtrace:
  ./build/debug/ponyc(ponyint_assert_fail+0x96) [0x85e4b6]
  ./build/debug/ponyc(pass_expr+0x51d) [0x7bbfcd]
  ./build/debug/ponyc(ast_visit+0x2a4) [0x7bc904]
  ./build/debug/ponyc(ast_visit+0x1e4) [0x7bc844]
  ./build/debug/ponyc(ast_visit+0x1e4) [0x7bc844]
  ./build/debug/ponyc(ast_visit+0x1e4) [0x7bc844]
  ./build/debug/ponyc(ast_visit+0x1e4) [0x7bc844]
  ./build/debug/ponyc(ast_visit+0x1e4) [0x7bc844]
  ./build/debug/ponyc(ast_visit+0x1e4) [0x7bc844]
  ./build/debug/ponyc(ast_visit+0x1e4) [0x7bc844]
  ./build/debug/ponyc() [0x7bd366]
  ./build/debug/ponyc() [0x7bcd8a]
  ./build/debug/ponyc(ast_passes_program+0x22) [0x7bc9d2]
  ./build/debug/ponyc(program_load+0xb8) [0x7df0e8]
  ./build/debug/ponyc() [0x76538c]
  ./build/debug/ponyc(main+0x261) [0x765241]
  /usr/lib/libc.so.6(__libc_start_main+0xd0) [0x7f1ffd34e780]
  ./build/debug/ponyc(_start+0x2a) [0x764f1a]

In addition, there seems to be a parse error if (error) is replaced by error,
as in let x: String = error

@jasoncarr0 jasoncarr0 changed the title Compiler assertion error when assigning variable using error and strange parse Compiler assertion error when assigning variable using error Aug 11, 2021
@SeanTAllen SeanTAllen added bug good first issue Good for newcomers help wanted Extra attention is needed labels Aug 17, 2021
@mikumikudice
Copy link

mikumikudice commented Sep 14, 2021

Investigating I found that the error occurs when is_typecheck_error returns true, while switching ast_id(ast). I don't know how the compiler actually works but I presume that when the function returns true without rising an error within the if block the crash happens. I also presume that matching as an expression and not an assignment is the reason that let x: String = error doesn't cause a crash too.

@jemc
Copy link
Member

jemc commented Sep 14, 2021

Thanks for looking into it!

I think we should add to that line you linked so that we not only return false, but also add a compilation error like this:

    ast_error(opt->check.errors, ast,
      "right side must be something that can be assigned");

@ergl
Copy link
Member

ergl commented Jan 30, 2022

In addition, there seems to be a parse error if (error) is replaced by error, as in let x: String = error

Should this be made into its own issue? The original error existed for other non-assignable expressions such as let x: String = (return), which should continue to be a parse error even when removing the parenthesis.

SeanTAllen pushed a commit that referenced this issue Jan 30, 2022
)

Builds upon @mateus-md work on #3894, fixes #3823.

When this is squashed and merged, the commit message should be "Fix compiler assertion failure when assigning error to a variable"
@SeanTAllen SeanTAllen removed the bug label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants