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...@@ -18804,9 +18804,12 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
18804 case ReqCompTimeYes:18804 case ReqCompTimeYes:
18805 var_class_requires_const = true;18805 var_class_requires_const = true;
18806 if (!var->gen_is_const && !is_comptime_var) {18806 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,
18808 buf_sprintf("variable of type '%s' must be const or comptime",18808 buf_sprintf("variable of type '%s' must be const or comptime",
18809 buf_ptr(&result_type->name)));18809 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 }
18810 result_type = ira->codegen->builtin_types.entry_invalid;18813 result_type = ira->codegen->builtin_types.entry_invalid;
18811 }18814 }
18812 break;18815 break;
test/compile_errors.zig+2
...@@ -6990,7 +6990,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -6990,7 +6990,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
6990 "tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime",6990 "tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime",
6991 "tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime",6991 "tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime",
6992 "tmp.zig:8:4: error: variable of type 'comptime_int' must be const or comptime",6992 "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",
6993 "tmp.zig:11:4: error: variable of type 'comptime_float' must be const or comptime",6994 "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",
6994 "tmp.zig:14:4: error: variable of type '(null)' must be const or comptime",6996 "tmp.zig:14:4: error: variable of type '(null)' must be const or comptime",
6995 "tmp.zig:17:4: error: variable of type 'Opaque' not allowed",6997 "tmp.zig:17:4: error: variable of type 'Opaque' not allowed",
6996 "tmp.zig:20:4: error: variable of type 'type' must be const or comptime",6998 "tmp.zig:20:4: error: variable of type 'type' must be const or comptime",