Skip to content

Commit 10de6c4

Browse files
vtjnashnalimilan
authored andcommitted
types: fix hash values of Vararg (#50932)
Fixes #50455 (cherry picked from commit c239e99)
1 parent 7885834 commit 10de6c4

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
@@ -1593,19 +1593,20 @@ static unsigned typekey_hash(jl_typename_t *tn, jl_value_t **key, size_t n, int
15931593
int failed = nofail;
15941594
for (j = 0; j < n; j++) {
15951595
jl_value_t *p = key[j];
1596+
size_t repeats = 1;
15961597
if (jl_is_vararg(p)) {
15971598
jl_vararg_t *vm = (jl_vararg_t*)p;
1598-
if (!nofail && vm->N)
1599-
return 0;
1600-
// 0x064eeaab is just a randomly chosen constant
1601-
hash = bitmix(vm->N ? type_hash(vm->N, &failed) : 0x064eeaab, hash);
1602-
if (failed && !nofail)
1603-
return 0;
1599+
if (vm->N && jl_is_long(vm->N))
1600+
repeats = jl_unbox_long(vm->N);
1601+
else
1602+
hash = bitmix(0x064eeaab, hash); // 0x064eeaab is just a randomly chosen constant
16041603
p = vm->T ? vm->T : (jl_value_t*)jl_any_type;
16051604
}
1606-
hash = bitmix(type_hash(p, &failed), hash);
1605+
unsigned hashp = type_hash(p, &failed);
16071606
if (failed && !nofail)
16081607
return 0;
1608+
while (repeats--)
1609+
hash = bitmix(hashp, hash);
16091610
}
16101611
hash = bitmix(~tn->hash, hash);
16111612
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)