Commit cf7de64f1a

pfg <pfg@pfg.pw>
2020-10-14 07:29:41
stage1: improve error for missing a number type on a runtime var
1 parent 663e112
Changed files (2)
src
stage1
test
src/stage1/ir.cpp
@@ -18804,9 +18804,12 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
     case ReqCompTimeYes:
         var_class_requires_const = true;
         if (!var->gen_is_const && !is_comptime_var) {
-            ir_add_error_node(ira, source_node,
+            ErrorMsg *msg = ir_add_error_node(ira, source_node,
                 buf_sprintf("variable of type '%s' must be const or comptime",
                     buf_ptr(&result_type->name)));
+            if(result_type->id == ZigTypeIdComptimeInt || result_type -> id == ZigTypeIdComptimeFloat) {
+                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"));
+            }
             result_type = ira->codegen->builtin_types.entry_invalid;
         }
         break;
test/compile_errors.zig
@@ -6990,7 +6990,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
         "tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime",
         "tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime",
         "tmp.zig:8:4: error: variable of type 'comptime_int' must be const or comptime",
+        "tmp.zig:8:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type",
         "tmp.zig:11:4: error: variable of type 'comptime_float' must be const or comptime",
+        "tmp.zig:11:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type",
         "tmp.zig:14:4: error: variable of type '(null)' must be const or comptime",
         "tmp.zig:17:4: error: variable of type 'Opaque' not allowed",
         "tmp.zig:20:4: error: variable of type 'type' must be const or comptime",