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...@@ -1376,6 +1376,10 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1376 fn_type_id.return_type = (fn_proto->return_type == nullptr) ?1376 fn_type_id.return_type = (fn_proto->return_type == nullptr) ?
1377 g->builtin_types.entry_void : analyze_type_expr(g, child_scope, fn_proto->return_type);1377 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
1379 if (fn_type_id.cc != CallingConventionUnspecified && !type_allowed_in_extern(g, fn_type_id.return_type)) {1383 if (fn_type_id.cc != CallingConventionUnspecified && !type_allowed_in_extern(g, fn_type_id.return_type)) {
1380 add_node_error(g, fn_proto->return_type,1384 add_node_error(g, fn_proto->return_type,
1381 buf_sprintf("return type '%s' not allowed in function with calling convention '%s'",1385 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...@@ -1386,7 +1390,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
13861390
1387 switch (fn_type_id.return_type->id) {1391 switch (fn_type_id.return_type->id) {
1388 case TypeTableEntryIdInvalid:1392 case TypeTableEntryIdInvalid:
1389 return g->builtin_types.entry_invalid;1393 zig_unreachable();
13901394
1391 case TypeTableEntryIdUndefLit:1395 case TypeTableEntryIdUndefLit:
1392 case TypeTableEntryIdNullLit:1396 case TypeTableEntryIdNullLit:
test/compile_errors.zig+4
...@@ -1,6 +1,10 @@...@@ -1,6 +1,10 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.CompileErrorContext) void {3pub 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
4 cases.add("function with non-extern enum parameter",8 cases.add("function with non-extern enum parameter",
5 \\const Foo = enum { A, B, C };9 \\const Foo = enum { A, B, C };
6 \\export fn entry(foo: Foo) void { }10 \\export fn entry(foo: Foo) void { }