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

Failed assertion on consuming a tuple accessor of a function result #3453

Closed
adri326 opened this issue Jan 25, 2020 · 2 comments · Fixed by #3647
Closed

Failed assertion on consuming a tuple accessor of a function result #3453

adri326 opened this issue Jan 25, 2020 · 2 comments · Fixed by #3647
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@adri326
Copy link
Member

adri326 commented Jan 25, 2020

The following code triggers an assertion fail:

actor Main
  new create(env: Env) =>
    let a = "I am a string"
    // commenting both lines or swapping the consume for a valid recover X ... end fixes the segfault
    consume a.chop(1)._1 // should be an error, as "a.chop(1)._1" is not a single identifier
    consume fn()._1 // same thing

  fun fn(): (U8, U8) =>
    (2, 3)

The error (on a debug build) being:

Building builtin -> packages/builtin
Building . -> 20-01-25--01
src/libponyc/pass/refer.c:135: generate_multi_dot_name: Assertion `0` failed.

Backtrace:
  build/debug/ponyc(ponyint_assert_fail+0xf1) [0x55f2ac99f4f7]
  build/debug/ponyc(+0x8c1dda) [0x55f2ac8d6dda]
  build/debug/ponyc(+0x8c4285) [0x55f2ac8d9285]
  build/debug/ponyc(pass_refer+0xda) [0x55f2ac8dad9c]
  build/debug/ponyc(ast_visit+0x28c) [0x55f2ac8c797a]
  build/debug/ponyc(ast_visit+0x1d1) [0x55f2ac8c78bf]
  build/debug/ponyc(ast_visit+0x1d1) [0x55f2ac8c78bf]
  build/debug/ponyc(ast_visit+0x1d1) [0x55f2ac8c78bf]
  build/debug/ponyc(ast_visit+0x1d1) [0x55f2ac8c78bf]
  build/debug/ponyc(ast_visit+0x1d1) [0x55f2ac8c78bf]
  build/debug/ponyc(ast_visit+0x1d1) [0x55f2ac8c78bf]
  build/debug/ponyc(ast_visit+0x1d1) [0x55f2ac8c78bf]
  build/debug/ponyc(+0x8b1db6) [0x55f2ac8c6db6]
  build/debug/ponyc(+0x8b223a) [0x55f2ac8c723a]
  build/debug/ponyc(ast_passes_program+0x28) [0x55f2ac8c74c5]
  build/debug/ponyc(program_load+0xc1) [0x55f2ac8c0f59]
  build/debug/ponyc(+0x89e9e3) [0x55f2ac8b39e3]
  build/debug/ponyc(main+0x1ce) [0x55f2ac8b3c46]
  /usr/lib/libc.so.6(__libc_start_main+0xf3) [0x7f23c7b0b153]
  build/debug/ponyc(_start+0x2e) [0x55f2ac8b386e]
[1]    25703 abort (core dumped)  build/debug/ponyc .
@mfelsche
Copy link
Contributor

The reason for this is that the code in the refer pass at refer.c is assuming it gets a nested reference, if it has something with a DOT at hand and tries to call a method generate_multi_dot_name that only supports nested references. If it hits a method call or similar, it simply asserts.

The solution i imagine is to verify a TK_DOT actually is a (possibly nested) field before calling that function and erroring out.

@mfelsche
Copy link
Contributor

Thanks for reporting btw! :)

@SeanTAllen SeanTAllen added help wanted Extra attention is needed bug good first issue Good for newcomers and removed bug: 3 - ready for work labels May 12, 2020
kapilash added a commit to kapilash/ponyc that referenced this issue Sep 9, 2020
Function calls in `consume` are deemed invalid by the syntax checker.
However, they seep in via field accessors on the function call
expressions. This change fixes ponylang#3453.
SeanTAllen pushed a commit that referenced this issue Sep 10, 2020
Function calls in `consume` are deemed invalid by the syntax checker.
However, they seep in via field accessors on the function call
expressions. This change fixes #3453.
kapilash added a commit to kapilash/ponyc that referenced this issue Sep 11, 2020
* `consume (consume variable).field` must result in similar compiation error as
* `consume (consume variable)`.
* `consume f().field` must result in similar compilation error as `consume
f()`
* `(consume f).b` must be treated as `consume f.b`

Fixes ponylang#3463, ponylang#3567 (and ponylang#3453)
kapilash added a commit to kapilash/ponyc that referenced this issue Sep 12, 2020
* `consume (consume variable).field` must result in a similar compillation error as
     `consume (consume variable)`.
* `consume f().field` must result in similar compilation error as `consume
f()`
* `(consume f).b` must be allowed and `f` should be moved.

Fixes ponylang#3463, ponylang#3567 (and ponylang#3453)
SeanTAllen pushed a commit that referenced this issue Sep 15, 2020
* `consume (consume variable).field` must result in a similar compillation error as
     `consume (consume variable)`.
* `consume f().field` must result in similar compilation error as `consume
f()`
* `(consume f).b` must be allowed and `f` should be moved.

Fixes #3463 
Fixes #3567 
Fixes #3453
@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 help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants