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(...@@ -18098,10 +18098,12 @@ fn explainWhyTypeIsComptime(
18098 .NoReturn,18098 .NoReturn,
18099 .Undefined,18099 .Undefined,
18100 .Null,18100 .Null,
18101 .Opaque,
18102 .Optional,
18103 => return,18101 => return,
1810418102
18103 .Opaque => {
18104 try mod.errNoteNonLazy(src_loc, msg, "opaque type '{}' has undefined size", .{ty.fmt(sema.mod)});
18105 },
18106
18105 .Array, .Vector => {18107 .Array, .Vector => {
18106 try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.elemType());18108 try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.elemType());
18107 },18109 },
...@@ -18124,6 +18126,10 @@ fn explainWhyTypeIsComptime(...@@ -18124,6 +18126,10 @@ fn explainWhyTypeIsComptime(
18124 try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.elemType());18126 try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.elemType());
18125 },18127 },
1812618128
18129 .Optional => {
18130 var buf: Type.Payload.ElemType = undefined;
18131 try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.optionalChild(&buf));
18132 },
18127 .ErrorUnion => {18133 .ErrorUnion => {
18128 try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.errorUnionPayload());18134 try sema.explainWhyTypeIsComptime(block, src, msg, src_loc, ty.errorUnionPayload());
18129 },18135 },
test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig+1
...@@ -40,5 +40,6 @@ const Opaque = opaque {};...@@ -40,5 +40,6 @@ const Opaque = opaque {};
40// :14:8: note: to modify this variable at runtime, it must be given an explicit fixed-size number type40// :14:8: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
41// :18:8: error: variable of type '@TypeOf(null)' must be const or comptime41// :18:8: error: variable of type '@TypeOf(null)' must be const or comptime
42// :22:19: error: values of type 'tmp.Opaque' must be comptime known, but operand value is runtime known42// :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
43// :26:8: error: variable of type 'type' must be const or comptime44// :26:8: error: variable of type 'type' must be const or comptime
44// :26:8: note: types are not available at runtime45// :26:8: note: types are not available at runtime