motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 648d34d8eacaf2e35e336abd5b0c50c2ab9bfc94 (tree)
parent b937a045607deae158ccb6a00f5defaf36510e61
Author: Veikka Tuominen <git@vexu.eu>
Date:   Thu, 27 Oct 2022 13:40:20 +0300

Sema: coerce zero-bit generic args are coerced properly

Closes #13307

Diffstat:
Msrc/Sema.zig | 2++
Atest/cases/compile_errors/zero-bit_generic_args_are_coerced_to_param_type.zig | 10++++++++++
2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -6738,6 +6738,8 @@ fn analyzeGenericCallArg( try sema.queueFullTypeResolution(param_ty); runtime_args[runtime_i.*] = casted_arg; runtime_i.* += 1; + } else if (try sema.typeHasOnePossibleValue(block, arg_src, comptime_arg.ty)) |_| { + _ = try sema.coerce(block, comptime_arg.ty, uncasted_arg, arg_src); } } diff --git a/test/cases/compile_errors/zero-bit_generic_args_are_coerced_to_param_type.zig b/test/cases/compile_errors/zero-bit_generic_args_are_coerced_to_param_type.zig @@ -0,0 +1,10 @@ +fn bar(a: anytype, _: @TypeOf(a)) void {} +pub export fn entry() void { + bar(@as(u0, 0), "fooo"); +} + +// error +// backend=stage2 +// target=native +// +// :3:21: error: expected type 'u0', found '*const [4:0]u8'