From 7257fa02528999a5fd0080d047bbab5df39209e9 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 13 Feb 2020 17:31:29 -0500 Subject: [PATCH] fix #34752, inference bug in varargs with constant prop --- base/compiler/inferenceresult.jl | 8 ++++++-- test/compiler/inference.jl | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/base/compiler/inferenceresult.jl b/base/compiler/inferenceresult.jl index a466a00df89df..24206369b3018 100644 --- a/base/compiler/inferenceresult.jl +++ b/base/compiler/inferenceresult.jl @@ -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) diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index b275cdf904757..15e03aefd6a1b 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -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