diff --git a/src/ir.cpp b/src/ir.cpp index 425ec733a8..2a8d6fe418 100644 --- 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 index ac20872fdc..1ef8543af3 100644 --- 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'"); } //////////////////////////////////////////////////////////////////////////////