Commit 1c6f415a64
Changed files (2)
src
src/ir.cpp
@@ -9682,8 +9682,12 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
if (type_is_invalid(elem_index->value.type))
return ira->codegen->builtin_types.entry_invalid;
- // This will be a pointer type because elem ptr IR instruction operates on a pointer to a thing.
TypeTableEntry *ptr_type = array_ptr->value.type;
+ if (ptr_type->id == TypeTableEntryIdMetaType) {
+ ir_add_error(ira, &elem_ptr_instruction->base,
+ buf_sprintf("array access of non-array type '%s'", buf_ptr(&ptr_type->name)));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
assert(ptr_type->id == TypeTableEntryIdPointer);
TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
test/compile_errors.zig
@@ -1853,4 +1853,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
,
".tmp_source.zig:3:5: error: float mode set twice for same scope",
".tmp_source.zig:2:5: note: first set here");
+
+ cases.add("array access of type",
+ \\export fn foo() {
+ \\ var b: u8[40] = undefined;
+ \\}
+ ,
+ ".tmp_source.zig:2:14: error: array access of non-array type 'type'");
}