Skip to content

Commit 5343130

Browse files
authored
Fix getfield_tfunc when order or boundscheck is Vararg (#57293)
Even if T has no intersection with the type we want, we don't know that we will throw because the arguments are optional. Fixes #57292.
1 parent dd13878 commit 5343130

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

β€ŽCompiler/src/tfuncs.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,17 +1073,15 @@ end
10731073
end
10741074

10751075
@nospecs function getfield_tfunc(𝕃::AbstractLattice, s00, name, boundscheck_or_order)
1076-
t = isvarargtype(boundscheck_or_order) ? unwrapva(boundscheck_or_order) :
1077-
widenconst(boundscheck_or_order)
1078-
hasintersect(t, Symbol) || hasintersect(t, Bool) || return Bottom
1076+
if !isvarargtype(boundscheck_or_order)
1077+
t = widenconst(boundscheck_or_order)
1078+
hasintersect(t, Symbol) || hasintersect(t, Bool) || return Bottom
1079+
end
10791080
return getfield_tfunc(𝕃, s00, name)
10801081
end
10811082
@nospecs function getfield_tfunc(𝕃::AbstractLattice, s00, name, order, boundscheck)
10821083
hasintersect(widenconst(order), Symbol) || return Bottom
1083-
if isvarargtype(boundscheck)
1084-
t = unwrapva(boundscheck)
1085-
hasintersect(t, Symbol) || hasintersect(t, Bool) || return Bottom
1086-
else
1084+
if !isvarargtype(boundscheck)
10871085
hasintersect(widenconst(boundscheck), Bool) || return Bottom
10881086
end
10891087
return getfield_tfunc(𝕃, s00, name)

β€ŽCompiler/test/inference.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6188,3 +6188,9 @@ end == Union{Float64,DomainError}
61886188
@test Compiler.argtypes_to_type(Any[ Int, UnitRange{Int}, Vararg{Pair{Any, Union{}}}, Float64 ]) === Tuple{Int, UnitRange{Int}, Float64}
61896189
@test Compiler.argtypes_to_type(Any[ Int, UnitRange{Int}, Vararg{Pair{Any, Union{}}}, Float64, Memory{2} ]) === Union{}
61906190
@test Base.return_types(Tuple{Tuple{Int, Vararg{Pair{Any, Union{}}}}},) do x; Returns(true)(x...); end |> only === Bool
6191+
6192+
# issue #57292
6193+
f57292(xs::Union{Tuple{String}, Int}...) = getfield(xs...)
6194+
g57292(xs::String...) = getfield(("abc",), 1, :not_atomic, xs...)
6195+
@test Base.infer_return_type(f57292) == String
6196+
@test Base.infer_return_type(g57292) == String

0 commit comments

Comments
Β (0)