authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-05 10:43:35-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-05 10:43:35-04:00
loga76a72469bf5980946fad8f8e60f07edde543ce5
tree8a4f5bba088b64e26d13c0e509bfd66ba3d64224
parent3e94650ef7bd2407fb0aca11ad19a93b90a14b7c
signaturelock-open Commit is signed but in an unrecognized format.

stage1: fix crash when invalid type used in array type

closes #1186

2 files changed, 17 insertions(+), 0 deletions(-)

src/ir.cpp+4
......@@ -15474,6 +15474,8 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA
1547415474static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
1547515475 IrInstructionArrayType *array_type_instruction)
1547615476{
15477 Error err;
15478
1547715479 IrInstruction *size_value = array_type_instruction->size->other;
1547815480 uint64_t size;
1547915481 if (!ir_resolve_usize(ira, size_value, &size))
......@@ -15515,6 +15517,8 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
1551515517 case TypeTableEntryIdBoundFn:
1551615518 case TypeTableEntryIdPromise:
1551715519 {
15520 if ((err = ensure_complete_type(ira->codegen, child_type)))
15521 return ira->codegen->builtin_types.entry_invalid;
1551815522 TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size);
1551915523 ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base);
1552015524 out_val->data.x_type = result_type;
test/compile_errors.zig+13
......@@ -1,6 +1,19 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "invalid type used in array type",
6 \\const Item = struct {
7 \\ field: SomeNonexistentType,
8 \\};
9 \\var items: [100]Item = undefined;
10 \\export fn entry() void {
11 \\ const a = items[0];
12 \\}
13 ,
14 ".tmp_source.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'",
15 );
16
417 cases.add(
518 "@noInlineCall on an inline function",
619 \\inline fn foo() void {}