Skip to content

Commit c239e99

Browse files
authored
types: fix hash values of Vararg (#50932)
Fixes #50455
1 parent 762801c commit c239e99

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/jltypes.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,19 +1597,20 @@ static unsigned typekey_hash(jl_typename_t *tn, jl_value_t **key, size_t n, int
15971597
int failed = nofail;
15981598
for (j = 0; j < n; j++) {
15991599
jl_value_t *p = key[j];
1600+
size_t repeats = 1;
16001601
if (jl_is_vararg(p)) {
16011602
jl_vararg_t *vm = (jl_vararg_t*)p;
1602-
if (!nofail && vm->N)
1603-
return 0;
1604-
// 0x064eeaab is just a randomly chosen constant
1605-
hash = bitmix(vm->N ? type_hash(vm->N, &failed) : 0x064eeaab, hash);
1606-
if (failed && !nofail)
1607-
return 0;
1603+
if (vm->N && jl_is_long(vm->N))
1604+
repeats = jl_unbox_long(vm->N);
1605+
else
1606+
hash = bitmix(0x064eeaab, hash); // 0x064eeaab is just a randomly chosen constant
16081607
p = vm->T ? vm->T : (jl_value_t*)jl_any_type;
16091608
}
1610-
hash = bitmix(type_hash(p, &failed), hash);
1609+
unsigned hashp = type_hash(p, &failed);
16111610
if (failed && !nofail)
16121611
return 0;
1612+
while (repeats--)
1613+
hash = bitmix(hashp, hash);
16131614
}
16141615
hash = bitmix(~tn->hash, hash);
16151616
return hash ? hash : 1;

test/tuple.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,3 +796,8 @@ namedtup = (;a=1, b=2, c=3)
796796
@test_throws ErrorException("Tuple field type cannot be Union{}") Tuple{Vararg{Union{},1}}
797797
@test Tuple{} <: Tuple{Vararg{Union{},N}} where N
798798
@test !(Tuple{} >: Tuple{Vararg{Union{},N}} where N)
799+
800+
@test Val{Tuple{T,T,T} where T} === Val{Tuple{Vararg{T,3}} where T}
801+
@test Val{Tuple{Vararg{T,4}} where T} === Val{Tuple{T,T,T,T} where T}
802+
@test Val{Tuple{Int64, Vararg{Int32,N}} where N} === Val{Tuple{Int64, Vararg{Int32}}}
803+
@test Val{Tuple{Int32, Vararg{Int64}}} === Val{Tuple{Int32, Vararg{Int64,N}} where N}

0 commit comments

Comments
 (0)