diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 2e344318f7..40c44846f3 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,25 @@ const tests = @import("tests.zig"); const builtin = @import("builtin"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add( + "asigning to struct or union fields that are not optionals with a function that returns an optional", + \\fn maybe(is: bool) ?u8 { + \\ if (is) return @as(u8, 10) else return null; + \\} + \\const U = union { + \\ Ye: u8, + \\}; + \\const S = struct { + \\ num: u8, + \\}; + \\export fn entry() void { + \\ var u = U{ .Ye = maybe(false) }; + \\ var s = S{ .num = maybe(false) }; + \\} + , + "tmp.zig:11:27: error: expected type 'u8', found '?u8'", + ); + cases.add( "missing result type for phi node", \\fn foo() !void {