zig

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

commit 5d935e1137ade5450e504ce9bc6bbf32301b0dfd (tree)
parent 75ec7d863efbba9dbb3eefa5e6607a5ef2fe8648
Author: mlugg <mlugg@mlugg.co.uk>
Date:   Thu,  6 Feb 2025 01:23:27 +0000

behavior: add test for old bug

Resolves: #18435

Diffstat:
Mtest/behavior/fn.zig | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/test/behavior/fn.zig b/test/behavior/fn.zig @@ -711,3 +711,20 @@ test "inline call propagates comptime-known argument to generic parameter and re try expect(a1 == 12340); try expect(b1 == 12340); } + +test "inline function return type is evaluated at comptime" { + const S = struct { + inline fn assertComptimeAndRet(x: anytype) @TypeOf(x) { + if (!@inComptime()) comptime unreachable; + return x; + } + + inline fn foo(val: anytype) assertComptimeAndRet(u16) { + return val; + } + }; + + const result = S.foo(123); + comptime assert(@TypeOf(result) == u16); + try expect(result == 123); +}