ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.93k stars 2.55k forks source link

Compiler crash with extern function returning opaque #21093

Open PauloCampana opened 3 months ago

PauloCampana commented 3 months ago

code:

const opq = opaque {};
extern fn fnname() opq;

test {
    _ = &fnname;
}

results:

$ zig version
0.13.0
$ zig test opaque.zig 
opaque.zig:2:20: error: opaque return type 'opaque.opq' not allowed
extern fn fnname() opq;
                   ^~~
opaque.zig:1:13: note: opaque declared here
const opq = opaque {};
            ^~~~~~~~~
$ zig14 version
0.14.0-dev.1080+da8fbcc2a
$ zig14 test opaque.zig 
Trace/breakpoint trap (core dumped)

Both compilers are x86_64 linux downloaded from the website

Vexu commented 3 months ago

It does cause a compile error but the function is still sent to the backend.

$ zig-dev test a.zig -fno-emit-bin 
a.zig:4:20: error: opaque return type 'a.opq' not allowed
extern fn fnname() opq;
                   ^~~
a.zig:3:13: note: opaque declared here
const opq = opaque {};
            ^~~~~~~~~