Skip to content

Commit

Permalink
Fix #36531 - Error in abstract_iteration (#36532)
Browse files Browse the repository at this point in the history
The issue here is passing a `Vargarg` to `precise_container_type`, which
doesn't really make sense. Instead, we need to have the caller unwrap
the vararg, request the precise container type of the inner type and
then re-wrap the answer in a vararg.

(cherry picked from commit 63179af)
  • Loading branch information
Keno authored and KristofferC committed Jul 10, 2020
1 parent 5d4b603 commit 678d57d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 17 additions & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ function abstract_iteration(@nospecialize(itft), @nospecialize(itertype), vtypes
else
return Any[Vararg{Any}]
end
@assert !isvarargtype(itertype)
stateordonet = abstract_call_known(iteratef, nothing, Any[itft, itertype], vtypes, sv)
# Return Bottom if this is not an iterator.
# WARNING: Changes to the iteration protocol must be reflected here,
Expand Down Expand Up @@ -591,7 +592,22 @@ function abstract_apply(@nospecialize(itft), @nospecialize(aft), aargtypes::Vect
for i = 1:nargs
ctypes´ = []
for ti in (splitunions ? uniontypes(aargtypes[i]) : Any[aargtypes[i]])
cti = precise_container_type(itft, ti, vtypes, sv)
if !isvarargtype(ti)
cti = precise_container_type(itft, ti, vtypes, sv)
else
cti = precise_container_type(itft, unwrapva(ti), vtypes, sv)
# We can't represent a repeating sequence of the same types,
# so tmerge everything together to get one type that represents
# everything.
argt = cti[end]
if isvarargtype(argt)
argt = unwrapva(argt)
end
for i in 1:(length(cti)-1)
argt = tmerge(argt, cti[i])
end
cti = Any[Vararg{argt}]
end
if _any(t -> t === Bottom, cti)
continue
end
Expand Down
5 changes: 5 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2602,3 +2602,8 @@ _use_unstable_kw_2() = _unstable_kw(x = 2, y = rand())
end
_construct_structwithsplatnew() = StructWithSplatNew(("",))
@test Base.return_types(_construct_structwithsplatnew) == Any[StructWithSplatNew]

# Issue #36531, double varargs in abstract_iteration
f36531(args...) = tuple((args...)...)
@test @inferred(f36531(1,2,3)) == (1,2,3)
@test code_typed(f36531, Tuple{Vararg{Int}}) isa Vector

0 comments on commit 678d57d

Please sign in to comment.