| author | |
| committer | |
| log | 6d0afc2bd233121d6b82f66cc09f74310a6eea4a |
| tree | bf2518175eb0b005a5c44c20c98ccf30b76d5bb0 |
| parent | 03b6d9f547417e1f56f5dfb5079f7aa2dee832a6 |
3 files changed, 12 insertions(+), 2 deletions(-)
src/ir.cpp+3-1| ... | ... | @@ -7858,6 +7858,8 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 7858 | 7858 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 7859 | 7859 | } |
| 7860 | 7860 | |
| 7861 | bool is_comptime_var = ir_get_var_is_comptime(var); | |
| 7862 | ||
| 7861 | 7863 | switch (result_type->id) { |
| 7862 | 7864 | case TypeTableEntryIdTypeDecl: |
| 7863 | 7865 | zig_unreachable(); |
| ... | ... | @@ -7865,7 +7867,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 7865 | 7867 | break; // handled above |
| 7866 | 7868 | case TypeTableEntryIdNumLitFloat: |
| 7867 | 7869 | case TypeTableEntryIdNumLitInt: |
| 7868 | if (is_export || is_extern || casted_init_value->value.special == ConstValSpecialRuntime) { | |
| 7870 | if (is_export || is_extern || (!var->src_is_const && !is_comptime_var)) { | |
| 7869 | 7871 | ir_add_error_node(ira, source_node, buf_sprintf("unable to infer variable type")); |
| 7870 | 7872 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 7871 | 7873 | } |
std/hash_map.zig+2-1| ... | ... | @@ -7,7 +7,8 @@ const Allocator = mem.Allocator; |
| 7 | 7 | const want_modification_safety = !@compileVar("is_release"); |
| 8 | 8 | const debug_u32 = if (want_modification_safety) u32 else void; |
| 9 | 9 | |
| 10 | pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn(key: K)->u32, | |
| 10 | pub fn HashMap(comptime K: type, comptime V: type, | |
| 11 | comptime hash: fn(key: K)->u32, | |
| 11 | 12 | comptime eql: fn(a: K, b: K)->bool) -> type |
| 12 | 13 | { |
| 13 | 14 | struct { |
test/run_tests.cpp+7| ... | ... | @@ -1697,6 +1697,13 @@ fn foo() { |
| 1697 | 1697 | } |
| 1698 | 1698 | fn bar() -> i32 { 0 } |
| 1699 | 1699 | )SOURCE", 1, ".tmp_source.zig:3:8: error: return value ignored"); |
| 1700 | ||
| 1701 | add_compile_fail_case("integer literal on a non-comptime var", R"SOURCE( | |
| 1702 | fn foo() { | |
| 1703 | var i = 0; | |
| 1704 | while (i < 10; i += 1) { } | |
| 1705 | } | |
| 1706 | )SOURCE", 1, ".tmp_source.zig:3:5: error: unable to infer variable type"); | |
| 1700 | 1707 | } |
| 1701 | 1708 | |
| 1702 | 1709 | ////////////////////////////////////////////////////////////////////////////// |