add regression test case

closes #3097
This commit is contained in:
Andrew Kelley 2019-11-18 17:31:35 -05:00
parent 4dd3f42972
commit 21aed86a4a
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9

View File

@ -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 {