Value: handle comparisons of runtime_values

Closes #15004
This commit is contained in:
Veikka Tuominen 2023-03-20 18:30:33 +02:00
parent 773b1c4c5c
commit 9d9815fb9c
2 changed files with 21 additions and 0 deletions

View File

@ -1113,6 +1113,10 @@ pub const Value = extern union {
.bool_true,
=> return BigIntMutable.init(&space.limbs, 1).toConst(),
.runtime_value => {
const sub_val = val.castTag(.runtime_value).?.data;
return sub_val.toBigIntAdvanced(space, target, opt_sema);
},
.int_u64 => return BigIntMutable.init(&space.limbs, val.castTag(.int_u64).?.data).toConst(),
.int_i64 => return BigIntMutable.init(&space.limbs, val.castTag(.int_i64).?.data).toConst(),
.int_big_positive => return val.castTag(.int_big_positive).?.asBigInt(),
@ -1979,6 +1983,12 @@ pub const Value = extern union {
.variable,
=> .gt,
.runtime_value => {
// This is needed to correctly handle hashing the value.
// Checks in Sema should prevent direct comparisons from reaching here.
const val = lhs.castTag(.runtime_value).?.data;
return val.orderAgainstZeroAdvanced(opt_sema);
},
.int_u64 => std.math.order(lhs.castTag(.int_u64).?.data, 0),
.int_i64 => std.math.order(lhs.castTag(.int_i64).?.data, 0),
.int_big_positive => lhs.castTag(.int_big_positive).?.asBigInt().orderAgainstScalar(0),

View File

@ -32,3 +32,14 @@ test "@src used as a comptime parameter" {
const T2 = S.Foo(@src());
try expect(T1 != T2);
}
test "@src in tuple passed to anytype function" {
const S = struct {
fn Foo(a: anytype) u32 {
return a[0].line;
}
};
const l1 = S.Foo(.{@src()});
const l2 = S.Foo(.{@src()});
try expect(l1 != l2);
}