@code_warntype gives yellow ::Union{Nothing, Tuple{Int64,Int64}} in for loops

Hello,

I’d have the following usage question.

If I have a function with a for loop inside, like:

function f()
    for i in 1:2
    end
end

And I call @code_warntype on it, i get a yellow line:

@code_warntype f()
Variables
  #self#::Core.Compiler.Const(f, false)
!  @_2::Union{Nothing, Tuple{Int64,Int64}}
  i::Int64

Body::Nothing
1 ─ %1  = (1:2)::Core.Compiler.Const(1:2, false)
│         (@_2 = Base.iterate(%1))
│   %3  = (@_2::Core.Compiler.Const((1, 1), false) === nothing)::Core.Compiler.Const(false, false)
│   %4  = Base.not_int(%3)::Core.Compiler.Const(true, false)
└──       goto #4 if not %4
2 ┄ %6  = @_2::Tuple{Int64,Int64}::Tuple{Int64,Int64}
│         (i = Core.getfield(%6, 1))
│   %8  = Core.getfield(%6, 2)::Int64
│         (@_2 = Base.iterate(%1, %8))
│   %10 = (@_2 === nothing)::Bool
│   %11 = Base.not_int(%10)::Bool
└──       goto #4 if not %11
3 ─       goto #2
4 ┄       return

( I did my best using this trick to make colored text in markdown)

So what does the yellow line mean? Is it something to be worried about? If so, how to fix it?

Thank you very much

4 Likes

The for loop returns that union always which is either the termination (nothing) or the text iterate. That is normal and you should not worry about it.

This is the section of the manual explaining the iterators’ interfaces.

5 Likes