Commit 21aed86a4a
Changed files (1)
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 {