diff --git a/src/analyze.cpp b/src/analyze.cpp index f46abe5e52..5a3551a7c2 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -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: diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 90fb547438..9a25bcce93 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -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 {