From 1c6f415a6416f8b29897393b8adfef45e1a2b51f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 21 May 2017 09:50:15 -0400 Subject: [PATCH] fix compiler crash when indexing types closes #376 --- src/ir.cpp | 6 +++++- test/compile_errors.zig | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ir.cpp b/src/ir.cpp index cc0e36448..0e089be1e 100644 --- a/src/ir.cpp +++ b/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; diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 999e1eaa6..86c6c5cc8 100644 --- a/test/compile_errors.zig +++ b/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'"); }