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) {
16061606 *result = false;
16071607 return ErrorNone;
16081608 }
1609 if (!type_is_nonnull_ptr(child_type)) {
1610 *result = false;
1611 return ErrorNone;
1612 }
16091613 return type_allowed_in_extern(g, child_type, result);
16101614 }
16111615 case ZigTypeIdEnum:
test/compile_errors.zig+10
......@@ -15,6 +15,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1515 "tmp.zig:5:9: error: duplicate switch value",
1616 );
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
1828 cases.add(
1929 "attempt to negate a non-integer, non-float or non-vector type",
2030 \\fn foo() anyerror!u32 {