commit ddd9624e2d03b71754e1591637f0f4f835c01a35 (tree)
parent eb9f1e2d532aa88199fb6afb3e2cfcef43c2ed14
Author: Andrew Kelley <superjoe30@gmail.com>
Date: Tue, 7 Mar 2017 19:08:02 -0500
fix assertion error, trying to dereference to array
thanks to hoppetosse on IRC for reporting the issue
Diffstat:
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/ir.cpp b/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);
}
diff --git a/test/run_tests.cpp b/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'");
}
//////////////////////////////////////////////////////////////////////////////