mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
Sema: better explanation why opaque types require comptime
This commit is contained in:
parent
3e2e6c108a
commit
3ceb27c840
10
src/Sema.zig
10
src/Sema.zig
@ -18098,10 +18098,12 @@ fn explainWhyTypeIsComptime(
|
||||
.NoReturn,
|
||||
.Undefined,
|
||||
.Null,
|
||||
.Opaque,
|
||||
.Optional,
|
||||
=> return,
|
||||
|
||||
.Opaque => {
|
||||
try mod.errNoteNonLazy(src_loc, msg, "opaque type '{}' has undefined size", .{ty.fmt(sema.mod)});
|
||||
},
|
||||
|
||||
.Array, .Vector => {
|
||||
try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.elemType());
|
||||
},
|
||||
@ -18124,6 +18126,10 @@ fn explainWhyTypeIsComptime(
|
||||
try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.elemType());
|
||||
},
|
||||
|
||||
.Optional => {
|
||||
var buf: Type.Payload.ElemType = undefined;
|
||||
try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.optionalChild(&buf));
|
||||
},
|
||||
.ErrorUnion => {
|
||||
try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.errorUnionPayload());
|
||||
},
|
||||
|
||||
@ -40,5 +40,6 @@ const Opaque = opaque {};
|
||||
// :14:8: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
|
||||
// :18:8: error: variable of type '@TypeOf(null)' must be const or comptime
|
||||
// :22:19: error: values of type 'tmp.Opaque' must be comptime known, but operand value is runtime known
|
||||
// :22:19: note: opaque type 'tmp.Opaque' has undefined size
|
||||
// :26:8: error: variable of type 'type' must be const or comptime
|
||||
// :26:8: note: types are not available at runtime
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user