authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-03-20 18:30:33+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-03-21 00:34:12+02:00
log9d9815fb9c21c91df41422ff582402fb56029328
tree99e2d8801e308d6c76c3901180ca6783d2c2ad28
parent773b1c4c5cdf9fde19cbf09d0f81f1bfe27ed7ca

Value: handle comparisons of runtime_values

Closes #15004

2 files changed, 21 insertions(+), 0 deletions(-)

src/value.zig+10
......@@ -1113,6 +1113,10 @@ pub const Value = extern union {
11131113 .bool_true,
11141114 => return BigIntMutable.init(&space.limbs, 1).toConst(),
11151115
1116 .runtime_value => {
1117 const sub_val = val.castTag(.runtime_value).?.data;
1118 return sub_val.toBigIntAdvanced(space, target, opt_sema);
1119 },
11161120 .int_u64 => return BigIntMutable.init(&space.limbs, val.castTag(.int_u64).?.data).toConst(),
11171121 .int_i64 => return BigIntMutable.init(&space.limbs, val.castTag(.int_i64).?.data).toConst(),
11181122 .int_big_positive => return val.castTag(.int_big_positive).?.asBigInt(),
......@@ -1979,6 +1983,12 @@ pub const Value = extern union {
19791983 .variable,
19801984 => .gt,
19811985
1986 .runtime_value => {
1987 // This is needed to correctly handle hashing the value.
1988 // Checks in Sema should prevent direct comparisons from reaching here.
1989 const val = lhs.castTag(.runtime_value).?.data;
1990 return val.orderAgainstZeroAdvanced(opt_sema);
1991 },
19821992 .int_u64 => std.math.order(lhs.castTag(.int_u64).?.data, 0),
19831993 .int_i64 => std.math.order(lhs.castTag(.int_i64).?.data, 0),
19841994 .int_big_positive => lhs.castTag(.int_big_positive).?.asBigInt().orderAgainstScalar(0),
test/behavior/src.zig+11
......@@ -32,3 +32,14 @@ test "@src used as a comptime parameter" {
3232 const T2 = S.Foo(@src());
3333 try expect(T1 != T2);
3434}
35
36test "@src in tuple passed to anytype function" {
37 const S = struct {
38 fn Foo(a: anytype) u32 {
39 return a[0].line;
40 }
41 };
42 const l1 = S.Foo(.{@src()});
43 const l2 = S.Foo(.{@src()});
44 try expect(l1 != l2);
45}