aiken-lang / aiken

A modern smart contract platform for Cardano
https://aiken-lang.org
Apache License 2.0
470 stars 91 forks source link

Compiler crashes with stack overflow #942

Closed t4ccer closed 4 months ago

t4ccer commented 4 months ago

What Git revision are you using?

v1.0.26-alpha compiled from 075668b5 and master as of today (b546e427) both crash

What operating system are you using, and which version?

Describe what the problem is?

Compiler crashes when compiling following code

fn not(x: Bool) -> Bool {
   when x is {
        True -> False
        False -> True
   }
}

type Identity<t> = t

test foo() {
   let id: Identity<fn(Bool) -> Bool> = not
   expect id.fst(True) // (sic!)
}
        Error aiken::check::unknown::record_field

  × While trying to make sense of your code...

thread 'main' has overflowed its stack
fatal runtime error: stack overflow

If you modify foo to use 1st instead of fst (still incorrect, I know) it stack overflows again but with different error

  × While trying to make sense of your code...
  ╰─▶ I tripped over an attempt to access elements on something that isn't indexable.

    ╭─[/home/t4ccer/repos/github/aiken-lang/aiken/examples/acceptance_tests/foo/lib/tests.ak:18:1]
 18 │    let id: Identity<fn(Bool) -> Bool> = not
 19 │    expect id.1st(True)
    ·           ──────
 20 │ }
    ╰────

thread 'main' has overflowed its stack
fatal runtime error: stack overflow

What should be the expected behavior?

Compiler does not crash, tells user that you cannot access a field on type synonym of a function.

KtorZ commented 4 months ago

Nice catch, keeps them coming 🙏