authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-21 09:50:15-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-21 09:50:15-04:00
log1c6f415a6416f8b29897393b8adfef45e1a2b51f
treed9ee346ad26a726978f5025225476e6232ed8008
parent565ac3e27acedcd8dd2e39eff07de571bbcc3a1b

fix compiler crash when indexing types

closes #376

2 files changed, 12 insertions(+), 1 deletions(-)

src/ir.cpp+5-1
......@@ -9682,8 +9682,12 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
96829682 if (type_is_invalid(elem_index->value.type))
96839683 return ira->codegen->builtin_types.entry_invalid;
96849684
9685 // This will be a pointer type because elem ptr IR instruction operates on a pointer to a thing.
96869685 TypeTableEntry *ptr_type = array_ptr->value.type;
9686 if (ptr_type->id == TypeTableEntryIdMetaType) {
9687 ir_add_error(ira, &elem_ptr_instruction->base,
9688 buf_sprintf("array access of non-array type '%s'", buf_ptr(&ptr_type->name)));
9689 return ira->codegen->builtin_types.entry_invalid;
9690 }
96879691 assert(ptr_type->id == TypeTableEntryIdPointer);
96889692
96899693 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
test/compile_errors.zig+7
......@@ -1853,4 +1853,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
18531853 ,
18541854 ".tmp_source.zig:3:5: error: float mode set twice for same scope",
18551855 ".tmp_source.zig:2:5: note: first set here");
1856
1857 cases.add("array access of type",
1858 \\export fn foo() {
1859 \\ var b: u8[40] = undefined;
1860 \\}
1861 ,
1862 ".tmp_source.zig:2:14: error: array access of non-array type 'type'");
18561863}