authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-26 10:37:18-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-26 10:37:18-05:00
logad3e2a5da07fbfe02e0152eb3fc408a7bcf36e3c
treea15ea8b33d5de33d545f9010eebb6d99be619c75
parentf7670882aff5fb3a943057edd9da34d053b5fe59

fix compiler crash on function with invalid return type

closes #722

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

src/analyze.cpp+5-1
......@@ -1376,6 +1376,10 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
13761376 fn_type_id.return_type = (fn_proto->return_type == nullptr) ?
13771377 g->builtin_types.entry_void : analyze_type_expr(g, child_scope, fn_proto->return_type);
13781378
1379 if (type_is_invalid(fn_type_id.return_type)) {
1380 return g->builtin_types.entry_invalid;
1381 }
1382
13791383 if (fn_type_id.cc != CallingConventionUnspecified && !type_allowed_in_extern(g, fn_type_id.return_type)) {
13801384 add_node_error(g, fn_proto->return_type,
13811385 buf_sprintf("return type '%s' not allowed in function with calling convention '%s'",
......@@ -1386,7 +1390,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
13861390
13871391 switch (fn_type_id.return_type->id) {
13881392 case TypeTableEntryIdInvalid:
1389 return g->builtin_types.entry_invalid;
1393 zig_unreachable();
13901394
13911395 case TypeTableEntryIdUndefLit:
13921396 case TypeTableEntryIdNullLit:
test/compile_errors.zig+4
......@@ -1,6 +1,10 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: &tests.CompileErrorContext) void {
4 cases.add("function with invalid return type",
5 \\export fn foo() boid {}
6 , ".tmp_source.zig:1:17: error: use of undeclared identifier 'boid'");
7
48 cases.add("function with non-extern enum parameter",
59 \\const Foo = enum { A, B, C };
610 \\export fn entry(foo: Foo) void { }