Skip to content

Failure to detect runtime-known argument passed to comptime parameter #16753

@ghost

Description

Zig Version

0.12.0-dev.25+36c57c3ba

Steps to Reproduce and Observed Behavior

test {
    const x = struct {
        fn x(sentinel: u8) void {
            var buf: [64]u8 = undefined;
            _ = @import("std").mem.sliceTo(&buf, sentinel);
        }
    }.x;
    x(0);
}

This fails to detect that sentinel is a runtime-known argument and cannot be passed to comptime parameter comptime end: meta.Elem(@TypeOf(ptr)) of std.mem.sliceTo:

$ zig test x.zig
Segmentation fault (core dumped)

It works when making sentinel a comptime parameter.

Expected Behavior

$ zig test x.zig
x.zig:7:31: error: runtime-known argument passed to comptime parameter
            _ = @import("std").mem.sliceTo(&buf, sentinel);
                                                 ^~~~~~~~
x.zig:13:39: note: declared comptime here
pub fn sliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) SliceTo(@TypeOf(ptr), end) {
                                      ^~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorerror messageThis issue points out an error message that is unhelpful and should be improved.frontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions