ponylang / ponyc

Pony is an open-source, actor-model, capabilities-secure, high performance programming language
http://www.ponylang.io
BSD 2-Clause "Simplified" License
5.71k stars 415 forks source link

ast_add_sibling: Assertion `new_sibling != NULL` failed. #2946

Open andrenth opened 5 years ago

andrenth commented 5 years ago

Hi

The (admittedly nonsense) code below triggers an assertion failure in ponyc:

use "collections"

type MyMap is MapIs[String, Array[String]]

class C
  let _m: MyMap

  new create() =>
    _m = MyMap

  fun foo(s: String) ? =>
    let a = _m(s)?
    bar(consume val a)

  fun bar(a: Array[String] val) =>
    None

Compiling with the latest ponyc from git, this leads to

$ ponyc -d
Building builtin -> /usr/local/lib/pony/0.25.0-ac6388696/packages/builtin
Building . -> /home/andre
Building collections -> /usr/local/lib/pony/0.25.0-ac6388696/packages/collections
Building ponytest -> /usr/local/lib/pony/0.25.0-ac6388696/packages/ponytest
Building time -> /usr/local/lib/pony/0.25.0-ac6388696/packages/time
src/libponyc/ast/ast.c:1371: ast_add_sibling: Assertion `new_sibling != NULL` failed.

Backtrace:
  ponyc(ponyint_assert_fail+0x90) [0x4dd2d0]
  ponyc(ast_add_sibling+0x1f9) [0x47ade9]
  ponyc(consume_type+0xc4) [0x453b64]
  ponyc(expr_consume+0xc3) [0x4a6b83]
  ponyc(pass_expr+0x2fb) [0x427ebb]
  ponyc(ast_visit+0x1c8) [0x420828]
  ponyc(ast_visit+0x170) [0x4207d0]
  ponyc(ast_visit+0x170) [0x4207d0]
  ponyc(ast_visit+0x170) [0x4207d0]
  ponyc(ast_visit+0x170) [0x4207d0]
  ponyc(ast_visit+0x170) [0x4207d0]
  ponyc(ast_visit+0x170) [0x4207d0]
  ponyc(ast_visit+0x170) [0x4207d0]
  ponyc(ast_visit+0x170) [0x4207d0]
  ponyc(ast_visit+0x170) [0x4207d0]
  ponyc() [0x420edd]
  ponyc(ast_passes_program+0x7e7) [0x422007]
  ponyc(program_load+0x74) [0x4433d4]
  ponyc(main+0x1ae) [0x41fe7e]
  /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f113b562830]
  ponyc(_start+0x29) [0x4202a9]
Theodus commented 5 years ago

More minimal example:

actor Main
  let a: Array[String ref] = []

  new create(env: Env) =>
    None

  fun foo() ? =>
    let s = a(0)?
    consume val s

Interesting note: replacing String ref with String tag results in no crash and the correct error message.