# Unexpected output for @which with keyword constructor

**URL:** <https://discourse.julialang.org/t/unexpected-output-for-which-with-keyword-constructor/24373>\
**Category:** General Usage\
**Created:** [May 19, 2019, 9:09am UTC](https://discourse.julialang.org/t/unexpected-output-for-which-with-keyword-constructor/24373 "2019-05-19T09:09:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [May 19, 2019, 9:09am UTC](https://discourse.julialang.org/t/unexpected-output-for-which-with-keyword-constructor/24373/1 "2019-05-19T09:09:25Z")

</div>

The output for `@which Hammer(weight = 25)` is not what I expected, nor is it consistent with the other invocations. Not sure if bug, known issue, or by design:

```julia
abstract type Product end

abstract type Tool <: Product end

struct Hammer <: Tool
       weight::Int
end

function Hammer(weight = 10)
       Hammer(weight)
end

function Hammer(; weight = 10)
       Hammer(weight)
end

@which Hammer(30)
Hammer(weight::Int64) # in Main at REPL[5]:2

@which Hammer()
Hammer() # in Main at REPL[53]:2

@which Hammer(weight = 25)
(::getfield(Core, Symbol("#kw#Type")))(::Any, ::Type{Hammer}) # in Main 😲

```

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [May 19, 2019, 9:51am UTC](https://discourse.julialang.org/t/unexpected-output-for-which-with-keyword-constructor/24373/2 "2019-05-19T09:51:29Z")

</div>

That’s just how keyword arguments are implemented – Julia creates a wrapper function:

```julia
julia> f(;x) = x
f (generic function with 1 method)

julia> @which f(x=3)
(::getfield(Main, Symbol("#kw##f")))(::Any, ::typeof(f)) in Main

```

IMHO `@which` shouldn’t try to be smart here and show you the method you defined, or anything like that.

---

<div class="post-metadata">

**Author:** ![essenciary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/essenciary/32/210469_2.png) [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Post date:** [May 19, 2019, 10:31am UTC](https://discourse.julialang.org/t/unexpected-output-for-which-with-keyword-constructor/24373/3 "2019-05-19T10:31:15Z")

</div>

I see, thank you.

Can’t comment as I don’t know how difficult would be to make `@which` smarter. However, this design exposes the internals of the implementation, which by itself is not useful nor desirable. It doesn’t really serve the purpose of `@which` - how is that useful to a user?

I stumbled into this while working on some code showcasing the usage of `@which` and this left my explanation hanging in mid-air.

Not a big deal but maybe it’s worth fixing, if not too difficult.
