fix compiler crash when indexing types

closes #376
master
Andrew Kelley 2017-05-21 09:50:15 -04:00
parent 565ac3e27a
commit 1c6f415a64
2 changed files with 12 additions and 1 deletions

View File

@ -9682,8 +9682,12 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
if (type_is_invalid(elem_index->value.type)) if (type_is_invalid(elem_index->value.type))
return ira->codegen->builtin_types.entry_invalid; 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; 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); assert(ptr_type->id == TypeTableEntryIdPointer);
TypeTableEntry *array_type = ptr_type->data.pointer.child_type; TypeTableEntry *array_type = ptr_type->data.pointer.child_type;

View File

@ -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:3:5: error: float mode set twice for same scope",
".tmp_source.zig:2:5: note: first set here"); ".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'");
} }