zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 21aed86a4a33b51857d82e4d8ed12ba3d4183de2 (tree)
parent 4dd3f429724768d575e297a82d633b4016467e72
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon, 18 Nov 2019 17:31:35 -0500

add regression test case

closes #3097

Diffstat:
Mtest/compile_errors.zig | 19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/test/compile_errors.zig b/test/compile_errors.zig @@ -3,6 +3,25 @@ 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 { \\ return anyerror.Foo;