Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explainWhyTypeIsComptime is extremely verbose #12344

Open
Vexu opened this issue Aug 6, 2022 · 0 comments
Open

explainWhyTypeIsComptime is extremely verbose #12344

Vexu opened this issue Aug 6, 2022 · 0 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. error message This issue points out an error message that is unhelpful and should be improved.
Milestone

Comments

@Vexu
Copy link
Member

Vexu commented Aug 6, 2022

Assigning the result of @typeInfo to a non-comptime variable:

test {
    var a = @typeInfo(u32);
    _ = a;
}

..will produce 159 lines of errors:

$ zig2 test a.zig
a.zig:2:9: error: variable of type 'builtin.Type' must be const or comptime
    var a = @typeInfo(u32);
        ^
./zig-out/lib/zig/std/builtin.zig:198:10: note: union requires comptime because of this field
    Int: Int,
         ^~~
./zig-out/lib/zig/std/builtin.zig:225:15: note: struct requires comptime because of this field
        bits: comptime_int,
              ^~~~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:199:12: note: union requires comptime because of this field
    Float: Float,
           ^~~~~
./zig-out/lib/zig/std/builtin.zig:232:15: note: struct requires comptime because of this field
        bits: comptime_int,
              ^~~~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:200:14: note: union requires comptime because of this field
    Pointer: Pointer,
             ^~~~~~~
./zig-out/lib/zig/std/builtin.zig:242:20: note: struct requires comptime because of this field
        alignment: comptime_int,
                   ^~~~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:244:16: note: struct requires comptime because of this field
        child: type,
               ^~~~
./zig-out/lib/zig/std/builtin.zig:244:16: note: types are not available at runtime
        child: type,
               ^~~~
./zig-out/lib/zig/std/builtin.zig:201:12: note: union requires comptime because of this field
    Array: Array,
           ^~~~~
./zig-out/lib/zig/std/builtin.zig:265:14: note: struct requires comptime because of this field
        len: comptime_int,
             ^~~~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:266:16: note: struct requires comptime because of this field
        child: type,
               ^~~~
./zig-out/lib/zig/std/builtin.zig:266:16: note: types are not available at runtime
        child: type,
               ^~~~
./zig-out/lib/zig/std/builtin.zig:202:13: note: union requires comptime because of this field
    Struct: Struct,
            ^~~~~~
./zig-out/lib/zig/std/builtin.zig:297:17: note: struct requires comptime because of this field
        fields: []const StructField,
                ^~~~~~~~~~~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:287:21: note: struct requires comptime because of this field
        field_type: type,
                    ^~~~
./zig-out/lib/zig/std/builtin.zig:287:21: note: types are not available at runtime
        field_type: type,
                    ^~~~
./zig-out/lib/zig/std/builtin.zig:290:20: note: struct requires comptime because of this field
        alignment: comptime_int,
                   ^~~~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:207:15: note: union requires comptime because of this field
    Optional: Optional,
              ^~~~~~~~
./zig-out/lib/zig/std/builtin.zig:305:16: note: struct requires comptime because of this field
        child: type,
               ^~~~
./zig-out/lib/zig/std/builtin.zig:305:16: note: types are not available at runtime
        child: type,
               ^~~~
./zig-out/lib/zig/std/builtin.zig:208:17: note: union requires comptime because of this field
    ErrorUnion: ErrorUnion,
                ^~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:311:20: note: struct requires comptime because of this field
        error_set: type,
                   ^~~~
./zig-out/lib/zig/std/builtin.zig:311:20: note: types are not available at runtime
        error_set: type,
                   ^~~~
./zig-out/lib/zig/std/builtin.zig:312:18: note: struct requires comptime because of this field
        payload: type,
                 ^~~~
./zig-out/lib/zig/std/builtin.zig:312:18: note: types are not available at runtime
        payload: type,
                 ^~~~
./zig-out/lib/zig/std/builtin.zig:210:11: note: union requires comptime because of this field
    Enum: Enum,
          ^~~~
./zig-out/lib/zig/std/builtin.zig:337:19: note: struct requires comptime because of this field
        tag_type: type,
                  ^~~~
./zig-out/lib/zig/std/builtin.zig:337:19: note: types are not available at runtime
        tag_type: type,
                  ^~~~
./zig-out/lib/zig/std/builtin.zig:338:17: note: struct requires comptime because of this field
        fields: []const EnumField,
                ^~~~~~~~~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:329:16: note: struct requires comptime because of this field
        value: comptime_int,
               ^~~~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:211:12: note: union requires comptime because of this field
    Union: Union,
           ^~~~~
./zig-out/lib/zig/std/builtin.zig:355:19: note: struct requires comptime because of this field
        tag_type: ?type,
                  ^~~~~
./zig-out/lib/zig/std/builtin.zig:355:19: note: types are not available at runtime
        tag_type: ?type,
                  ^~~~~
./zig-out/lib/zig/std/builtin.zig:356:17: note: struct requires comptime because of this field
        fields: []const UnionField,
                ^~~~~~~~~~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:347:21: note: struct requires comptime because of this field
        field_type: type,
                    ^~~~
./zig-out/lib/zig/std/builtin.zig:347:21: note: types are not available at runtime
        field_type: type,
                    ^~~~
./zig-out/lib/zig/std/builtin.zig:348:20: note: struct requires comptime because of this field
        alignment: comptime_int,
                   ^~~~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:212:9: note: union requires comptime because of this field
    Fn: Fn,
        ^~
./zig-out/lib/zig/std/builtin.zig:367:20: note: struct requires comptime because of this field
        alignment: comptime_int,
                   ^~~~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:371:22: note: struct requires comptime because of this field
        return_type: ?type,
                     ^~~~~
./zig-out/lib/zig/std/builtin.zig:371:22: note: types are not available at runtime
        return_type: ?type,
                     ^~~~~
./zig-out/lib/zig/std/builtin.zig:372:15: note: struct requires comptime because of this field
        args: []const Param,
              ^~~~~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:379:23: note: struct requires comptime because of this field
            arg_type: ?type,
                      ^~~~~
./zig-out/lib/zig/std/builtin.zig:379:23: note: types are not available at runtime
            arg_type: ?type,
                      ^~~~~
./zig-out/lib/zig/std/builtin.zig:213:14: note: union requires comptime because of this field
    BoundFn: Fn,
             ^~
./zig-out/lib/zig/std/builtin.zig:216:15: note: union requires comptime because of this field
    AnyFrame: AnyFrame,
              ^~~~~~~~
./zig-out/lib/zig/std/builtin.zig:398:16: note: struct requires comptime because of this field
        child: ?type,
               ^~~~~
./zig-out/lib/zig/std/builtin.zig:398:16: note: types are not available at runtime
        child: ?type,
               ^~~~~
./zig-out/lib/zig/std/builtin.zig:217:13: note: union requires comptime because of this field
    Vector: Vector,
            ^~~~~~
./zig-out/lib/zig/std/builtin.zig:404:14: note: struct requires comptime because of this field
        len: comptime_int,
             ^~~~~~~~~~~~
./zig-out/lib/zig/std/builtin.zig:405:16: note: struct requires comptime because of this field
        child: type,
               ^~~~
./zig-out/lib/zig/std/builtin.zig:405:16: note: types are not available at runtime
        child: type,
               ^~~~

.. which is a bit excessive.

I think it should either only report the first comptime field or just drop all the other notes after a certain limit and mention that there were more reasons.

Follow up to #12324

@Vexu Vexu added the error message This issue points out an error message that is unhelpful and should be improved. label Aug 6, 2022
@Vexu Vexu added this to the 0.11.0 milestone Aug 6, 2022
@andrewrk andrewrk added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Aug 7, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. error message This issue points out an error message that is unhelpful and should be improved.
Projects
None yet
Development

No branches or pull requests

2 participants