authorgravatar for pfg@pfg.pwpfg <pfg@pfg.pw> 2020-10-13 22:29:41-07:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-11-18 21:45:51+02:00
logcf7de64f1a136c9208284362db6cc1d3c81f1111
tree602f18d3b83d39d83a76e0d082b9a25d24bf3bc0
parent663e112773f91ccbff9f9825147b1a2c0bb5e00c

stage1: improve error for missing a number type on a runtime var


2 files changed, 6 insertions(+), 1 deletions(-)

src/stage1/ir.cpp+4-1
......@@ -18804,9 +18804,12 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
1880418804 case ReqCompTimeYes:
1880518805 var_class_requires_const = true;
1880618806 if (!var->gen_is_const && !is_comptime_var) {
18807 ir_add_error_node(ira, source_node,
18807 ErrorMsg *msg = ir_add_error_node(ira, source_node,
1880818808 buf_sprintf("variable of type '%s' must be const or comptime",
1880918809 buf_ptr(&result_type->name)));
18810 if(result_type->id == ZigTypeIdComptimeInt || result_type -> id == ZigTypeIdComptimeFloat) {
18811 add_error_note(ira->codegen, msg, source_node, buf_sprintf("to modify this variable at runtime, it must be given an explicit fixed-size number type"));
18812 }
1881018813 result_type = ira->codegen->builtin_types.entry_invalid;
1881118814 }
1881218815 break;
test/compile_errors.zig+2
......@@ -6990,7 +6990,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
69906990 "tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime",
69916991 "tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime",
69926992 "tmp.zig:8:4: error: variable of type 'comptime_int' must be const or comptime",
6993 "tmp.zig:8:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type",
69936994 "tmp.zig:11:4: error: variable of type 'comptime_float' must be const or comptime",
6995 "tmp.zig:11:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type",
69946996 "tmp.zig:14:4: error: variable of type '(null)' must be const or comptime",
69956997 "tmp.zig:17:4: error: variable of type 'Opaque' not allowed",
69966998 "tmp.zig:20:4: error: variable of type 'type' must be const or comptime",