mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
stage1: improve error for missing a number type on a runtime var
This commit is contained in:
parent
663e112773
commit
cf7de64f1a
@ -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;
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user