Commit ddd9624e2d

Andrew Kelley <superjoe30@gmail.com>
2017-03-08 01:08:02
fix assertion error, trying to dereference to array
thanks to hoppetosse on IRC for reporting the issue
1 parent eb9f1e2
Changed files (2)
src/ir.cpp
@@ -9399,7 +9399,12 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
     if (type_is_invalid(value->value.type))
         return value->value.type;
 
-    assert(ptr->value.type->id == TypeTableEntryIdPointer);
+    if (ptr->value.type->id != TypeTableEntryIdPointer) {
+        ir_add_error(ira, ptr,
+            buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name)));
+        return ira->codegen->builtin_types.entry_invalid;
+    }
+
     if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) {
         return ir_analyze_void(ira, &store_ptr_instruction->base);
     }
test/run_tests.cpp
@@ -1704,6 +1704,15 @@ fn foo() {
     while (i < 10; i += 1) { }
 }
     )SOURCE", 1, ".tmp_source.zig:3:5: error: unable to infer variable type");
+
+    add_compile_fail_case("dereference an array", R"SOURCE(
+var s_buffer: [10]u8 = undefined;
+pub fn pass(in: []u8) -> []u8 {
+    var out = &s_buffer;
+    *out[0] = in[0];
+    return (*out)[0...1];
+}
+    )SOURCE", 1, ".tmp_source.zig:5:5: error: attempt to dereference non pointer type '[10]u8'");
 }
 
 //////////////////////////////////////////////////////////////////////////////