Skip to content

@compileError for unsupported int widths fails to compile itself #34

Description

@lalinsky

packInt and getIntSize both end their signed and unsigned branches with a @compileError that itself does not compile:

@compileError("Unsupported signed int with " ++ type_info.int.bits ++ "bits");

type_info.int.bits is a u16, and ++ needs indexable operands, so the concatenation fails before the message is ever produced. Asking for an unsupported width gives:

src/int.zig:99:70: error: expected indexable; found 'u16'
        @compileError("Unsupported signed int with " ++ type_info.int.bits ++ "bits");
                                                        ~~~~~~~~~~~~~^~~~~

instead of the intended "Unsupported signed int with 96 bits". Reproduces with packInt(&w, i96, 1).

Four sites: the signed and unsigned branches of packInt, and the same two in getIntSize. std.fmt.comptimePrint produces the message properly. There is also a missing space before bits in the intended text.

Never surfaced because nothing instantiates these functions with an unsupported width — the same reason #21, #22 and the stale .Slice in #23 stayed hidden.

Worth noting what this blocks in practice: std.Io.Timestamp and std.Io.Duration are both struct { nanoseconds: i96 }, so encoding either one lands exactly here. A clear error message would at least make that legible. (Supporting them is a separate question — msgpack integers stop at 64 bits, so i96 cannot round-trip in general, and the timestamp extension would be the real answer for Timestamp.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions