jakt icon indicating copy to clipboard operation
jakt copied to clipboard

Array creation in functions that can't throw errors generates invalid cpp

Open HectorPeeters opened this issue 2 years ago • 2 comments

When allocating arrays in functions that don't return an error type, the compiler generates incorrect cpp code as it uses the TRY macro.

It might also be nice to annotate that the main function returns and ErrorOr<T> as that is not clear from the current syntax. In the example below, it looks like the two functions both return void but in main, the array allocation generates correct code while in test if does not.

Example:

function test() {
    let mutable data = [0u32; 256]
}

function main() {
    test()
}

HectorPeeters avatar May 20 '22 15:05 HectorPeeters

Arguable this is a typechecker bug more that a codegen one, as the compiler should point out that a fallible operation (array creation) inside a function no marked throws is not permitted unless explicitly ignored (made "infallible", a.k.a crashing).

linusg avatar May 21 '22 12:05 linusg

See #153

linusg avatar May 21 '22 12:05 linusg

fixed as of d73ef3e

there is now an error message "Array initialization inside non-throwing scope"

lanmonster avatar Aug 16 '22 15:08 lanmonster