# Incorrect results from \`@which\` and \`@code\_warntype\` for literal powers

**URL:** https://discourse.julialang.org/t/incorrect-results-from-which-and-code-warntype-for-literal-powers/2630
**Category:** General Usage
**Created:** [March 13, 2017, 3:12am UTC](https://discourse.julialang.org/t/incorrect-results-from-which-and-code-warntype-for-literal-powers/2630 "2017-03-13T03:12:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [March 13, 2017, 3:12am UTC](https://discourse.julialang.org/t/incorrect-results-from-which-and-code-warntype-for-literal-powers/2630/1 "2017-03-13T03:12:28Z")

</div>

I’m trying to use the new literal exponent behavior introduced in [https://github.com/JuliaLang/julia/pull/20530](https://github.com/JuliaLang/julia/pull/20530) and [https://github.com/JuliaLang/julia/pull/20889](https://github.com/JuliaLang/julia/pull/20889). I think I’m correctly overloading `literal_pow`, but various macros like `@which`, `@code_warntype` and others all seem to be showing me the wrong behavior.

```julia
julia> immutable MyType
           x::Int
       end

julia> import Base: literal_pow

julia> literal_pow(^, m::MyType, ::Type{Val{p}}) where p = m.x + p
literal_pow (generic function with 6 methods)

julia> m = MyType(1)
MyType(1)

julia> m^2
3

```

That’s all good so far. But none of the introspection macros seem to work for `m^2`:

```julia
julia> @which m^2
^(x, p::Integer) in Base at intfuncs.jl:196

julia> @code_warntype m^2
Variables:
  #self#::Base.#^
  x::MyType
  p::Int64

Body:
  begin
      return $(Expr(:invoke, MethodInstance for power_by_squaring(::MyType, ::Int64), :(Base.power_by_squaring), :(x), :(p)))
  end::Any

julia> @code_lowered m^2
CodeInfo(:(begin
        nothing
        return (Base.power_by_squaring)(x, p)
    end))

julia> using Base.Test

julia> @inferred m^2
ERROR: MethodError: no method matching *(::MyType, ::MyType)
Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...) at operators.jl:424
Stacktrace:
 [1] power_by_squaring(::MyType, ::Int64) at ./intfuncs.jl:166
 [2] ^(::MyType, ::Int64) at ./intfuncs.jl:196

```

are the special lowering rules not being applied inside the macros?

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [March 14, 2017, 4:15am UTC](https://discourse.julialang.org/t/incorrect-results-from-which-and-code-warntype-for-literal-powers/2630/2 "2017-03-14T04:15:08Z")

</div>

Issue created: [`@which` and `@code_warntype` don't show `^Val{p}` lowering · Issue #21014 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/21014)
