authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-11 16:33:37+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-11 18:47:29+03:00
log3ceb27c8401df17e5a7f522d68104da79501b5b6
tree0d44ceba53ed381488abec59232d4368b8f9ac4c
parent3e2e6c108a4306ed890b3034e2ad47c8d4caf2f7

Sema: better explanation why opaque types require comptime


2 files changed, 9 insertions(+), 2 deletions(-)

src/Sema.zig+8-2
......@@ -18098,10 +18098,12 @@ fn explainWhyTypeIsComptime(
1809818098 .NoReturn,
1809918099 .Undefined,
1810018100 .Null,
18101 .Opaque,
18102 .Optional,
1810318101 => return,
1810418102
18103 .Opaque => {
18104 try mod.errNoteNonLazy(src_loc, msg, "opaque type '{}' has undefined size", .{ty.fmt(sema.mod)});
18105 },
18106
1810518107 .Array, .Vector => {
1810618108 try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.elemType());
1810718109 },
......@@ -18124,6 +18126,10 @@ fn explainWhyTypeIsComptime(
1812418126 try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.elemType());
1812518127 },
1812618128
18129 .Optional => {
18130 var buf: Type.Payload.ElemType = undefined;
18131 try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.optionalChild(&buf));
18132 },
1812718133 .ErrorUnion => {
1812818134 try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.errorUnionPayload());
1812918135 },
test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig+1
......@@ -40,5 +40,6 @@ const Opaque = opaque {};
4040// :14:8: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
4141// :18:8: error: variable of type '@TypeOf(null)' must be const or comptime
4242// :22:19: error: values of type 'tmp.Opaque' must be comptime known, but operand value is runtime known
43// :22:19: note: opaque type 'tmp.Opaque' has undefined size
4344// :26:8: error: variable of type 'type' must be const or comptime
4445// :26:8: note: types are not available at runtime