Skip to content

Segfault when assigning comptime fixed type function to comptime anytype function #21497

@Veeloxfire

Description

@Veeloxfire

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

(also fails using whatever version zig trunk on godbolt is using, but I wasnt sure exactly which that was so I put the version I currently have installed where it also fails)

Compile this code

const GenericFn = fn(comptime anytype)void;

fn foo(comptime _: i32) void {}

const f: GenericFn = foo;

pub fn main() void {
    _ = f(0);
}

https://godbolt.org/z/haEjaGqf7

Returns either "error code 5" or "SIGSEV" depending on setup

Expected Behavior

Im not sure what specifically I expect it to do, but I dont expect it to segfault

I suspect it should be a compile error (given it is for the non-comptime case) and that makes the most sense to me. But Im not 100% sure the intended behaviour isnt that this works, so I thought I'd report here instead of the "error message" section.

I'm pretty sure its const f: GenericFn = foo; thats segfaulting since _ = @TypeOf(f); also causes a segfault and that doesnt call it. (removing both doesnt segfault but I assume thats because its not instantiated)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions