Skip to content

Commit 438485e

Browse files
authored
fix #34752, inference bug in varargs with constant prop (#34755)
1 parent 521eda8 commit 438485e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

base/compiler/inferenceresult.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ function matching_cache_argtypes(linfo::MethodInstance, given_argtypes::Vector)
3535
if linfo.def.isva
3636
isva_given_argtypes = Vector{Any}(undef, nargs)
3737
for i = 1:(nargs - 1)
38-
isva_given_argtypes[i] = given_argtypes[i]
38+
isva_given_argtypes[i] = argtype_by_index(given_argtypes, i)
39+
end
40+
if length(given_argtypes) >= nargs || !isvarargtype(given_argtypes[end])
41+
isva_given_argtypes[nargs] = tuple_tfunc(given_argtypes[nargs:end])
42+
else
43+
isva_given_argtypes[nargs] = tuple_tfunc(given_argtypes[end:end])
3944
end
40-
isva_given_argtypes[nargs] = tuple_tfunc(given_argtypes[nargs:end])
4145
given_argtypes = isva_given_argtypes
4246
end
4347
cache_argtypes, overridden_by_const = matching_cache_argtypes(linfo, nothing)

test/compiler/inference.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,3 +2492,14 @@ struct X33954
24922492
end
24932493
f33954(x) = rand(Bool) ? f33954((x,)) : x
24942494
@test Base.return_types(f33954, Tuple{X33954})[1] >: X33954
2495+
2496+
# issue #34752
2497+
struct a34752{T} end
2498+
function a34752(c, d...)
2499+
length(d) > 1 || error()
2500+
end
2501+
function h34752()
2502+
g = Tuple[(42, Any[42][1], 42)][1]
2503+
a34752(g...)
2504+
end
2505+
@test h34752() === true

0 commit comments

Comments
 (0)