Skip to content

assertion failed trying to specialize function that invokes closure passed as a struct field #60

@wizzard0

Description

@wizzard0

Note the @ in call to fac; removing it makes the code compile fine

impala: /home/user/anydsl/thorin/src/thorin/be/llvm/llvm.cpp:988: llvm::Type* thorin::CodeGen::convert(const thorin::Type*): Assertion `ret' failed.
Aborted (core dumped)
type char = u8;
type str = [char];


extern "C" {
    fn atoi(&str) -> int;
    fn print_int(int) -> ();
}


fn subber(a: int, b: int) -> int {
	a - b
}

fn invocator(a:fn(int) -> int, b: int) -> int {
	a(b)
}

fn fac_rec(n : int, d:explicit_delegate)->int {
    if (n <= 0) {
        1
    } else {
        n * fac_rec(d.callable(n), d)
    }
}

struct explicit_delegate {
    callable: fn(int) -> int
}

fn fac_nrec(n : int, delta: int) -> int {
    let subber1 = |x: int| subber(x, delta);
    let ci = explicit_delegate{
        callable : subber1
    };
    @fac_rec(n, ci)
}

fn main(argc: int, argv: &[&str]) -> int {
    let n = if argc >= 2 { atoi(argv(1)) } else { 1 };
    let res = fac_nrec(10, n);
    print_int(res);
    res
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions