Prevent crash with invalid extern type

Fixes #3240
master
LemonBoy 2019-09-18 08:54:59 +02:00 committed by Andrew Kelley
parent db988f42a7
commit 663e665843
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 14 additions and 0 deletions

View File

@ -1606,6 +1606,10 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {
*result = false;
return ErrorNone;
}
if (!type_is_nonnull_ptr(child_type)) {
*result = false;
return ErrorNone;
}
return type_allowed_in_extern(g, child_type, result);
}
case ZigTypeIdEnum:

View File

@ -15,6 +15,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
"tmp.zig:5:9: error: duplicate switch value",
);
cases.add(
"invalid optional type in extern struct",
\\const stroo = extern struct {
\\ moo: ?[*c]u8,
\\};
\\export fn testf(fluff: *stroo) void {}
,
"tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'",
);
cases.add(
"attempt to negate a non-integer, non-float or non-vector type",
\\fn foo() anyerror!u32 {