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 {...@@ -1113,6 +1113,10 @@ pub const Value = extern union {
1113 .bool_true,1113 .bool_true,
1114 => return BigIntMutable.init(&space.limbs, 1).toConst(),1114 => 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 },
1116 .int_u64 => return BigIntMutable.init(&space.limbs, val.castTag(.int_u64).?.data).toConst(),1120 .int_u64 => return BigIntMutable.init(&space.limbs, val.castTag(.int_u64).?.data).toConst(),
1117 .int_i64 => return BigIntMutable.init(&space.limbs, val.castTag(.int_i64).?.data).toConst(),1121 .int_i64 => return BigIntMutable.init(&space.limbs, val.castTag(.int_i64).?.data).toConst(),
1118 .int_big_positive => return val.castTag(.int_big_positive).?.asBigInt(),1122 .int_big_positive => return val.castTag(.int_big_positive).?.asBigInt(),
...@@ -1979,6 +1983,12 @@ pub const Value = extern union {...@@ -1979,6 +1983,12 @@ pub const Value = extern union {
1979 .variable,1983 .variable,
1980 => .gt,1984 => .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 },
1982 .int_u64 => std.math.order(lhs.castTag(.int_u64).?.data, 0),1992 .int_u64 => std.math.order(lhs.castTag(.int_u64).?.data, 0),
1983 .int_i64 => std.math.order(lhs.castTag(.int_i64).?.data, 0),1993 .int_i64 => std.math.order(lhs.castTag(.int_i64).?.data, 0),
1984 .int_big_positive => lhs.castTag(.int_big_positive).?.asBigInt().orderAgainstScalar(0),1994 .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" {...@@ -32,3 +32,14 @@ test "@src used as a comptime parameter" {
32 const T2 = S.Foo(@src());32 const T2 = S.Foo(@src());
33 try expect(T1 != T2);33 try expect(T1 != T2);
34}34}
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}