Skip to content

bug: codegen emits sizeof(__auto_type) when appending function references to [func] arrays #1558

@SchoolyB

Description

@SchoolyB

Description

When function references are appended to a [func] array via arrays.append(), codegen emits sizeof(__auto_type) to determine element size. __auto_type is not valid inside sizeof() in C.

Repro

import @arrays

do is_pos(n int) -> bool { return n > 0 }
do is_neg(n int) -> bool { return n < 0 }

do main() {
    mut preds [func(int) -> bool] = {}
    arrays.append(preds, ()is_pos)
    arrays.append(preds, ()is_neg)
    println(preds[0](5))
}

Expected: Compiles and prints true.

Actual: C compilation error — sizeof(__auto_type) is not valid.

Root cause

The element type switch in emit_arrays_call() for append and insert_at didn't handle TK_FUNCTION. Function references fell through to the __auto_type default. Since func refs are stored as void* in arrays, the correct C type is void *.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcodegenRelated to C code generation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions