commit 3ceb27c8401df17e5a7f522d68104da79501b5b6 (tree)
parent 3e2e6c108a4306ed890b3034e2ad47c8d4caf2f7
Author: Veikka Tuominen <git@vexu.eu>
Date: Mon, 11 Jul 2022 16:33:37 +0300
Sema: better explanation why opaque types require comptime
Diffstat:
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/Sema.zig b/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());
},
diff --git a/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig b/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig
@@ -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