zig

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

commit 0c33ebb38eeb383da62a8af8aa368e8f6cac63a2 (tree)
parent 9eed0d3603c9ff04902e199ef358aba4bd7489f3
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon, 18 Nov 2019 19:59:03 -0500

add regression test case. closes #2980

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( + "regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", + \\const Foo = struct { + \\ ptr: ?*usize, + \\ uval: u32, + \\}; + \\fn get_uval(x: u32) !u32 { + \\ return error.NotFound; + \\} + \\export fn entry() void { + \\ const afoo = Foo{ + \\ .ptr = null, + \\ .uval = get_uval(42), + \\ }; + \\} + , + "tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'", + ); + + 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;