Commit c1af360532
Changed files (2)
src
src/ir.cpp
@@ -14874,8 +14874,13 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
if (type_is_invalid(container_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
+ if (container_ptr->value.type->id != ZigTypeIdPointer) {
+ ir_add_error_node(ira, field_ptr_instruction->base.source_node,
+ buf_sprintf("attempt to dereference non-pointer type '%s'",
+ buf_ptr(&container_ptr->value.type->name)));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
ZigType *container_type = container_ptr->value.type->data.pointer.child_type;
- assert(container_ptr->value.type->id == ZigTypeIdPointer);
Buf *field_name = field_ptr_instruction->field_name_buffer;
if (!field_name) {
test/compile_errors.zig
@@ -1,6 +1,16 @@
const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
+ cases.add(
+ "deref slice and get len field",
+ \\export fn entry() void {
+ \\ var a: []u8 = undefined;
+ \\ _ = a.*.len;
+ \\}
+ ,
+ ".tmp_source.zig:3:12: error: attempt to dereference non-pointer type '[]u8'",
+ );
+
cases.add(
"@ptrCast a 0 bit type to a non- 0 bit type",
\\export fn entry() bool {