authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-09-18 08:54:59+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-23 17:30:28-04:00
log663e665843627cead40258a74ffddf4574fbb816
treeadb2f8bb7a31a7a0fd7903a7f71485f4056a0c86
parentdb988f42a7ac1ce0ec65fde0e7ea94009b1d7238
signaturelock-open Commit is signed but in an unrecognized format.

Prevent crash with invalid extern type

Fixes #3240

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

src/analyze.cpp+4
...@@ -1606,6 +1606,10 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {...@@ -1606,6 +1606,10 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {
1606 *result = false;1606 *result = false;
1607 return ErrorNone;1607 return ErrorNone;
1608 }1608 }
1609 if (!type_is_nonnull_ptr(child_type)) {
1610 *result = false;
1611 return ErrorNone;
1612 }
1609 return type_allowed_in_extern(g, child_type, result);1613 return type_allowed_in_extern(g, child_type, result);
1610 }1614 }
1611 case ZigTypeIdEnum:1615 case ZigTypeIdEnum:
test/compile_errors.zig+10
...@@ -15,6 +15,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -15,6 +15,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
15 "tmp.zig:5:9: error: duplicate switch value",15 "tmp.zig:5:9: error: duplicate switch value",
16 );16 );
1717
18 cases.add(
19 "invalid optional type in extern struct",
20 \\const stroo = extern struct {
21 \\ moo: ?[*c]u8,
22 \\};
23 \\export fn testf(fluff: *stroo) void {}
24 ,
25 "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'",
26 );
27
18 cases.add(28 cases.add(
19 "attempt to negate a non-integer, non-float or non-vector type",29 "attempt to negate a non-integer, non-float or non-vector type",
20 \\fn foo() anyerror!u32 {30 \\fn foo() anyerror!u32 {