Skip to content

Commit

Permalink
fix #34752, inference bug in varargs with constant prop
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Feb 13, 2020
1 parent 3058112 commit 7257fa0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions base/compiler/inferenceresult.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ function matching_cache_argtypes(linfo::MethodInstance, given_argtypes::Vector)
if linfo.def.isva
isva_given_argtypes = Vector{Any}(undef, nargs)
for i = 1:(nargs - 1)
isva_given_argtypes[i] = given_argtypes[i]
isva_given_argtypes[i] = argtype_by_index(given_argtypes, i)
end
if length(given_argtypes) >= nargs || !isvarargtype(given_argtypes[end])
isva_given_argtypes[nargs] = tuple_tfunc(given_argtypes[nargs:end])
else
isva_given_argtypes[nargs] = tuple_tfunc(given_argtypes[end:end])
end
isva_given_argtypes[nargs] = tuple_tfunc(given_argtypes[nargs:end])
given_argtypes = isva_given_argtypes
end
cache_argtypes, overridden_by_const = matching_cache_argtypes(linfo, nothing)
Expand Down
11 changes: 11 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2492,3 +2492,14 @@ struct X33954
end
f33954(x) = rand(Bool) ? f33954((x,)) : x
@test Base.return_types(f33954, Tuple{X33954})[1] >: X33954

# issue #34752
struct a34752{T} end
function a34752(c, d...)
length(d) > 1 || error()
end
function h34752()
g = Tuple[(42, Any[42][1], 42)][1]
a34752(g...)
end
@test h34752() === true

0 comments on commit 7257fa0

Please sign in to comment.