# @which not working on .+

**URL:** <https://discourse.julialang.org/t/which-not-working-on/32673>\
**Category:** New to Julia\
**Created:** [December 24, 2019, 11:56pm UTC](https://discourse.julialang.org/t/which-not-working-on/32673 "2019-12-24T23:56:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuxi.liu](https://avatars.discourse-cdn.com/v4/letter/y/839c29/32.png) [@yuxi.liu](https://discourse.julialang.org/u/yuxi.liu)\
**Post date:** [December 24, 2019, 11:56pm UTC](https://discourse.julialang.org/t/which-not-working-on/32673/1 "2019-12-24T23:56:08Z")

</div>

Why is this failing?

```julia
julia> @which [2 3] .+ [1 2]
ERROR: UndefVarError: .+ not defined

```

---

<div class="post-metadata">

**Author:** ![bashonubuntu](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bashonubuntu](https://discourse.julialang.org/u/bashonubuntu)\
**Post date:** [December 25, 2019, 12:14am UTC](https://discourse.julialang.org/t/which-not-working-on/32673/2 "2019-12-25T00:14:12Z")

</div>

What’s your desired output?

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [December 25, 2019, 12:36am UTC](https://discourse.julialang.org/t/which-not-working-on/32673/3 "2019-12-25T00:36:30Z")

</div>

The problem is that at a parser level `a .+ b` is recognized as just a regular `call` expression, and the lowering to a broadcast call is actually done at the lowering stage. Therefore, `@which` thinks this is a call to the function `var".+"`, which, of course, doesn’t exist. You could open an issue, because it should at least give a better error. Dot syntax is lowered to `Base.materialize(Base.broadcasted(+, a, b))`, so `@which` could maybe give the location of the `Base.materialize` call here, but I don’t know how useful that would be.

---

<div class="post-metadata">

**Author:** ![yuxi.liu](https://avatars.discourse-cdn.com/v4/letter/y/839c29/32.png) [@yuxi.liu](https://discourse.julialang.org/u/yuxi.liu)\
**Post date:** [December 25, 2019, 12:45am UTC](https://discourse.julialang.org/t/which-not-working-on/32673/4 "2019-12-25T00:45:53Z")

</div>

My intuition is something like `a .+ b` gets changed to `broadcasted_+(a, b)`, and was hoping it would return something like  
`broadcasted_+(a::Array{Int64}...)`  
but now I see it wouldn’t make sense.

The error message could be made to say something like  
`Did you mean '@which broadcast(+, a, b)'?`

---

<div class="post-metadata">

**Author:** ![waldyrious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/waldyrious/32/80_2.png) [@waldyrious](https://discourse.julialang.org/u/waldyrious)\
**Post date:** [December 25, 2019, 11:00pm UTC](https://discourse.julialang.org/t/which-not-working-on/32673/5 "2019-12-25T23:00:46Z")

</div>

I agree it would make sense and be more consistent with similar uses of `@which`:

```julia
julia> @which 1 + 2
+(x::T, y::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} in Base at int.jl:53

julia> @which [1 2] + [3 4]
+(A::Array, Bs::Array...) in Base at arraymath.jl:44

julia> @which [1 2] .+ [3 4]
ERROR: UndefVarError: .+ not defined
Stacktrace:
 [1] top-level scope at REPL[3]:1

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 26, 2019, 10:32am UTC](https://discourse.julialang.org/t/which-not-working-on/32673/6 "2019-12-26T10:32:35Z")

</div>

I think that the implementation of `@which` (specifically, the internal `InteractiveUtils.gen_call_with_extracted_types`) actually calls `Meta.lower`, but that case just slips through somehow (I didn’t look into this in depth).

In any case, the right behavior would be giving an informative error message.
