diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-03-25 18:27:10 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-03-26 00:27:12 -0400 |
| commit | bae35bdf2d8919b60dee9a0af3afbdd93dd72b59 (patch) | |
| tree | bff6e4b5f81840d82febef78b28e75d9dc1083e3 /test/behavior | |
| parent | bcd7eb012ac3d4a6365eea0b69aa89b0aef57243 (diff) | |
| download | zig-bae35bdf2d8919b60dee9a0af3afbdd93dd72b59.tar.gz zig-bae35bdf2d8919b60dee9a0af3afbdd93dd72b59.zip | |
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.
Diffstat (limited to 'test/behavior')
| -rw-r--r-- | test/behavior/call.zig | 20 |
1 files changed, 20 insertions, 0 deletions
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, + }); +} |
