# Inference problem with findall

**URL:** <https://discourse.julialang.org/t/inference-problem-with-findall/73262>\
**Category:** General Usage\
**Tags:** inference\
**Created:** [December 17, 2021, 2:00pm UTC](https://discourse.julialang.org/t/inference-problem-with-findall/73262 "2021-12-17T14:00:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![etienne\_dg](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@etienne\_dg](https://discourse.julialang.org/u/etienne_dg)\
**Post date:** [December 17, 2021, 2:00pm UTC](https://discourse.julialang.org/t/inference-problem-with-findall/73262/1 "2021-12-17T14:00:34Z")

</div>

Hi, the following code is not correctly inferred in julia 1.7.0.

```julia
function test()
    k = 1
    if k == 1
        k = 2
    end
    return findall(x -> x >= k, [1])
end

```

```julia
julia> @code_warntype(test())
MethodInstance for test()
  from test() in Main at none:1
Arguments
  #self#::Core.Const(test)
Locals
  #17::var"#17#18"
  k@_3::Core.Box
  k@_4::Union{}
Body::Any
1 ─ Core.NewvarNode(:(#17))
│ (k@_3 = Core.Box())
│ Core.setfield!(k@_3, :contents, 1)
│ %4 = Core.isdefined(k@_3, :contents)::Bool
└── goto #3 if not %4
2 ─ goto #4
3 ─ Core.NewvarNode(:(k@_4))
└── k@_4
4 ┄ %9 = Core.getfield(k@_3, :contents)::Any
│ %10 = (%9 == 1)::Any
└── goto #6 if not %10
5 ─ Core.setfield!(k@_3, :contents, 2)
6 ┄ (#17 = %new(Main.:(var"#17#18"), k@_3))
│ %14 = #17::var"#17#18"
│ %15 = Base.vect(1)::Vector{Int64}
│ %16 = Main.findall(%14, %15)::Any
└── return %16

```

It is correctly inferred in julia 1.6.1 to an `Int64[]`.  
Is it expected or should I file an issue ?

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [December 17, 2021, 2:22pm UTC](https://discourse.julialang.org/t/inference-problem-with-findall/73262/2 "2021-12-17T14:22:07Z")

</div>

> [@etienne\_dg](#):
>
> ```julia
> function test()
> k = 1
> if k == 1
> k = 2
> end
> return findall(x -> x >= k, [1])
> end
> 
> ```

Hi @etienne_dg , I am getting correct type inferencing with this function on my Mac (macOS Catalina 10.15.7).  
Here is the output and details of my Julia installation:

```julia
➜ julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.7.0 (2021-11-30)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> function test()
           k = 1
           if k == 1
               k = 2
           end
           return findall(x -> x >= k, [1])
       end
test (generic function with 1 method)

julia> test() |> typeof
Vector{Int64} (alias for Array{Int64, 1})

```

Also, I get this as the output of the function

```julia
julia> test()
Int64[]

```

---

<div class="post-metadata">

**Author:** ![etienne\_dg](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@etienne\_dg](https://discourse.julialang.org/u/etienne_dg)\
**Post date:** [December 17, 2021, 2:27pm UTC](https://discourse.julialang.org/t/inference-problem-with-findall/73262/3 "2021-12-17T14:27:37Z")

</div>

Strange, I built this as a MWE of [failing tests in Graphs.jl](https://github.com/JuliaGraphs/Graphs.jl/actions/runs/1592424033), and it fails for every OS.

I tested my example on Ubuntu 20.04

---

<div class="post-metadata">

**Author:** ![etienne\_dg](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@etienne\_dg](https://discourse.julialang.org/u/etienne_dg)\
**Post date:** [December 17, 2021, 2:34pm UTC](https://discourse.julialang.org/t/inference-problem-with-findall/73262/4 "2021-12-17T14:34:11Z")

</div>

What do you get if you try `@code_warntype(test())` or `@inferred test()`?  
I get the same as you with :

```julia
julia> test() |> typeof
Vector{Int64} (alias for Array{Int64, 1})

```

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [December 17, 2021, 2:36pm UTC](https://discourse.julialang.org/t/inference-problem-with-findall/73262/5 "2021-12-17T14:36:45Z")

</div>

This is not about `findall` but captured values in [closures](https://github.com/JuliaLang/julia/issues/15276).

---

<div class="post-metadata">

**Author:** ![etienne\_dg](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@etienne\_dg](https://discourse.julialang.org/u/etienne_dg)\
**Post date:** [December 17, 2021, 2:38pm UTC](https://discourse.julialang.org/t/inference-problem-with-findall/73262/6 "2021-12-17T14:38:06Z")

</div>

I thought about it but it was working on julia 1.6, what is going on 1.7 ?
