diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-03-02 18:51:19 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-03-02 18:51:19 -0500 |
| commit | 6d0afc2bd233121d6b82f66cc09f74310a6eea4a (patch) | |
| tree | bf2518175eb0b005a5c44c20c98ccf30b76d5bb0 /src | |
| parent | 03b6d9f547417e1f56f5dfb5079f7aa2dee832a6 (diff) | |
| download | zig-6d0afc2bd233121d6b82f66cc09f74310a6eea4a.tar.gz zig-6d0afc2bd233121d6b82f66cc09f74310a6eea4a.zip | |
add compile error for assigning number literal to non-comptime var
Diffstat (limited to 'src')
| -rw-r--r-- | src/ir.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index fb1670fe82..425ec733a8 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -7858,6 +7858,8 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc result_type = ira->codegen->builtin_types.entry_invalid; } + bool is_comptime_var = ir_get_var_is_comptime(var); + switch (result_type->id) { case TypeTableEntryIdTypeDecl: zig_unreachable(); @@ -7865,7 +7867,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc break; // handled above case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdNumLitInt: - if (is_export || is_extern || casted_init_value->value.special == ConstValSpecialRuntime) { + if (is_export || is_extern || (!var->src_is_const && !is_comptime_var)) { ir_add_error_node(ira, source_node, buf_sprintf("unable to infer variable type")); result_type = ira->codegen->builtin_types.entry_invalid; } |
