Open
Description
function foo(x)
a = x ? (1,2) : nothing
a::Tuple
a[1]
end
@code_warntype foo(true)
Variables:
x::Bool
a::Union{Nothing, Tuple{Int64,Int64}}
#temp#@_4::Union{Nothing, Tuple{Int64,Int64}}
#temp#@_5::Int64
Body:
begin
unless x::Bool goto 4
#temp#@_4::Union{Nothing, Tuple{Int64,Int64}} = (1, 2)
goto 6
4:
#temp#@_4::Union{Nothing, Tuple{Int64,Int64}} = Main.nothing
6:
a::Union{Nothing, Tuple{Int64,Int64}} = #temp#@_4::Union{Nothing, Tuple{Int64,Int64}}
#= line 3 =#
(Core.typeassert)(a::Union{Nothing, Tuple{Int64,Int64}}, Main.Tuple)::Tuple{Int64,Int64}
#= line 4 =#
SSAValue(1) = (a::Union{Nothing, Tuple{Int64,Int64}} isa Tuple{Int64,Int64})::Bool
unless SSAValue(1) goto 15
#temp#@_5::Int64 = $(Expr(:invoke, MethodInstance for getindex(::Tuple{Int64,Int64}, ::Int64), :(Main.getindex), :(a), 1))::Int64
goto 20
15:
goto 17
17:
#temp#@_5::Int64 = (Main.getindex)(a::Union{Nothing, Tuple{Int64,Int64}}, 1)::Int64
goto 20
20:
SSAValue(0) = #temp#@_5::Int64
return SSAValue(0)
end::Int64
There should be a TypedSlot on the getindex
since we know that after the typeassert a
can't be nothing
.