# Properly query methods of a function?

**URL:** <https://discourse.julialang.org/t/properly-query-methods-of-a-function/30178>\
**Category:** General Usage\
**Created:** [October 22, 2019, 3:46pm UTC](https://discourse.julialang.org/t/properly-query-methods-of-a-function/30178 "2019-10-22T15:46:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [October 22, 2019, 3:46pm UTC](https://discourse.julialang.org/t/properly-query-methods-of-a-function/30178/1 "2019-10-22T15:46:30Z")

</div>

```julia
    sig_params(t::UnionAll) = sig_params(t.body)
    sig_params(t::DataType) = t.parameters[2:end]
    abstract type AT2{T<:Real} end
    f(x::AT2{Float64}) = "AT2{Float64}"
    f(x::T) where T<:AT2 = "T<:AT2"
   
julia> methods(f)
# 2 methods for generic function "f":
[1] f(x::AT2{Float64}) in Main at REPL[4]:1
[2] f(x::T) where T<:AT2 in Main at REPL[5]:1

julia> sig = methods(f).ms[2].sig
Tuple{typeof(f),T} where T<:AT2

julia> methods(f,sig_params(sig))
# 2 methods for generic function "f":
[1] f(x::AT2{Float64}) in Main at REPL[4]:1
[2] f(x::T) where T<:AT2 in Main at REPL[5]:1

julia> code_lowered(f,sig_params(sig))
2-element Array{Core.CodeInfo,1}:
 CodeInfo(
1 ─ return "AT2{Float64}"
)
 CodeInfo(
1 ─ return "T<:AT2"
)

```

what is the proper signature to query only the second method “[2] f(x::T) where T\<:AT2” ?

one more question, the results of methods and code\_lowered, do they correspond one to one always with proper order?

thanks

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [October 22, 2019, 5:31pm UTC](https://discourse.julialang.org/t/properly-query-methods-of-a-function/30178/2 "2019-10-22T17:31:05Z")

</div>

```julia
julia> methods(f, Tuple{AT2{Int}})
# 1 method for generic function "f":
[1] f(x::T) where T<:AT2 in Main at REPL[3]:1

```

And I don’t believe you can get method to return only the less specific one.

Why do you need this? Why can’t you just use the current result from `methods`?

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [October 22, 2019, 5:58pm UTC](https://discourse.julialang.org/t/properly-query-methods-of-a-function/30178/3 "2019-10-22T17:58:18Z")

</div>

> [@Qiyamah](#):
>
> one more question, the results of methods and code\_lowered, do they correspond one to one always with proper order?

what about this one?  
Thanks for your reply.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [October 22, 2019, 6:18pm UTC](https://discourse.julialang.org/t/properly-query-methods-of-a-function/30178/4 "2019-10-22T18:18:56Z")

</div>

They should have the same order although I’m not sure if that’ll be guaranteed.
