From bae35bdf2d8919b60dee9a0af3afbdd93dd72b59 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 25 Mar 2022 18:27:10 -0700 Subject: stage2: result location types for function call arguments * AstGen: restore the param_type ZIR instruction and pass it to the expression for function call arguments. This does not solve the problem for generic function parameters, but it catches stage2 up to stage1 which also does not solve the problem for generic function parameters. - Most of the enhancements in this commit will still be needed for a more sophisticated further improvement to handle generic function types. - In Sema, handling of `as` coercion recognizes the `var_args_param` Type Tag and passes the operand through doing no coercion. - That was the last ZIR tag and we are now using all 256 ZIR tags. * AstGen: array init and struct init expressions use the anon form even when the result location has a type. Prevents the type system incorrectly believing, for example, that a tuple is actually an array when the result location is a param_type of a function with `anytype` parameter. * Sema: add missing coercion in `unionInit` to coerce the init to the corresponding union field type. * `Value.fieldValue` now takes a type and does not take an allocator. closes #11293 After this commit, stage2 passes all the parser tests. --- test/behavior/call.zig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test') diff --git a/test/behavior/call.zig b/test/behavior/call.zig index 57bc0fb3f7..119dc289b1 100644 --- a/test/behavior/call.zig +++ b/test/behavior/call.zig @@ -98,3 +98,23 @@ test "comptime call with bound function as parameter" { var inst: S = undefined; try expectEqual(?i32, S.ReturnType(inst.call_me_maybe)); } + +test "result location of function call argument through runtime condition and struct init" { + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + + const E = enum { a, b }; + const S = struct { + e: E, + }; + const namespace = struct { + fn foo(s: S) !void { + try expect(s.e == .b); + } + }; + var runtime = true; + try namespace.foo(.{ + .e = if (!runtime) .a else .b, + }); +} -- cgit v1.2.3