mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 05:20:34 +00:00
fix assertion error, trying to dereference to array
thanks to hoppetosse on IRC for reporting the issue
This commit is contained in:
parent
eb9f1e2d53
commit
ddd9624e2d
@ -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);
|
||||
}
|
||||
|
||||
@ -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'");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user