Skip to content

Commit 19d2f4c

Browse files
committed
Fix a precision issue in abstract_iteration
The first loop is left before `valtype` and `statetype` are updated from the current `stateordonet`, so the second loop should first process it before obtaining a new one instead of vice versa. Fixes #41022.
1 parent e87e30c commit 19d2f4c

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,6 @@ function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @n
863863
statetype = widenconst(statetype)
864864
valtype = widenconst(valtype)
865865
while valtype !== Any
866-
stateordonet = abstract_call_known(interp, iteratef, nothing, Any[Const(iteratef), itertype, statetype], sv).rt
867866
stateordonet = widenconst(stateordonet)
868867
nounion = typesubtract(stateordonet, Nothing, 0)
869868
if !isa(nounion, DataType) || !(nounion <: Tuple) || isvatuple(nounion) || length(nounion.parameters) != 2
@@ -879,6 +878,7 @@ function abstract_iteration(interp::AbstractInterpreter, @nospecialize(itft), @n
879878
end
880879
valtype = tmerge(valtype, nounion.parameters[1])
881880
statetype = tmerge(statetype, nounion.parameters[2])
881+
stateordonet = abstract_call_known(interp, iteratef, nothing, Any[Const(iteratef), itertype, statetype], sv).rt
882882
end
883883
push!(ret, Vararg{valtype})
884884
return ret, nothing

test/compiler/inference.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,6 +2875,7 @@ partial_return_2(x) = Val{partial_return_1(x)[2]}
28752875
# Precision of abstract_iteration
28762876
f_splat(x) = (x...,)
28772877
@test Base.return_types(f_splat, (Pair{Int,Int},)) == Any[Tuple{Int, Int}]
2878+
@test Base.return_types(f_splat, (UnitRange{Int},)) == Any[Tuple{Vararg{Int}}]
28782879

28792880
# issue #32699
28802881
f32699(a) = (id = a[1],).id

0 commit comments

Comments
 (0)