Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-sensical MethodError #5559

Closed
simonster opened this issue Jan 26, 2014 · 3 comments
Closed

non-sensical MethodError #5559

simonster opened this issue Jan 26, 2014 · 3 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@simonster
Copy link
Member

The tests for DSP.jl master are currently failing with a MethodError (JuliaDSP/DSP.jl#19):

 ERROR: no method convert(Type{Array{Complex{Float64},1}}, Array{Float64,1})

That method definitely exists: We are importing convert from Base before extending it, and inserting print(code_lowered(convert, (Type{Array{Complex{Float64},1}}, Array{Float64,1}))) above the line that throws shows the method source. git bisect shows that the error first appears with 6002358 (cc @JeffBezanson).

@johnmyleswhite
Copy link
Member

Maybe related to the convert issue I raised a week or two ago?

@simonster
Copy link
Member Author

For the method that's throwing, code_typed shows:

code_typed(convert, (Type{ZPKFilter}, TFFilter{Float64}))
1-element Array{Any,1}:
 :($(Expr(:lambda, {:#s68,:f}, {{:k,:b,:z,:p},{{:#s68,Type{ZPKFilter{Z,P,K}},0},{:f,TFFilter{Float64},0},{:k,Float64,18},{:b,Poly{Float64},18},{:z,Array{Complex{Float64},1},18},{:p,Array{Complex{Float64},1},18}},{}}, quote  # /Users/simon/.julia/DSP/src/filter_design.jl, line 107:
        k = arrayref(top(getfield)(top(getfield)(f::TFFilter{Float64},:b)::Poly{Float64},:a)::Array{Float64,1},top(box)(Int64,top(add_int)(1,top(getfield)(top(getfield)(f::TFFilter{Float64},:b)::Poly{Float64},:nzfirst)::Int64))::Int64)::Float64 # line 108:
        b = /(top(getfield)(f::TFFilter{Float64},:b)::Poly{Float64},k::Float64)::Poly{Float64} # line 109:
        z = convert_default($(Array{Complex{Float64},1}),roots(b::Poly{Float64})::AbstractArray{T,N},convert)::Array{Complex{Float64},1} # line 110:
        p = convert_default($(Array{Complex{Float64},1}),roots(top(getfield)(f::TFFilter{Float64},:a)::Poly{Float64})::AbstractArray{T,N},convert)::Array{Complex{Float64},1} # line 111:
        return $(Expr(:new, ZPKFilter{Complex{Float64},Complex{Float64},Float64}, :(z::Array{Complex{Float64},1}), :(p::Array{Complex{Float64},1}), :(k::Float64)))::ZPKFilter{Complex{Float64},Complex{Float64},Float64}
    end)))

It fails at the convert_default line there, since Array{Float64,1} is not a subtype of Array{Complex{Float64},1}. With the previous (working) commit, code_typed shows:

code_typed(convert, (Type{ZPKFilter}, TFFilter{Float64}))
1-element Array{Any,1}:
 :($(Expr(:lambda, {:#s62,:f}, {{:k,:b,:z,:p},{{:#s62,Type{ZPKFilter{Z,P,K}},0},{:f,TFFilter{Float64},0},{:k,Float64,18},{:b,Poly{Float64},18},{:z,Array{Complex{Float64},1},18},{:p,Array{Complex{Float64},1},18}},{}}, quote  # /Users/simon/.julia/DSP/src/filter_design.jl, line 107:
        k = arrayref(top(getfield)(top(getfield)(f::TFFilter{Float64},:b)::Poly{Float64},:a)::Array{Float64,1},top(box)(Int64,top(add_int)(1,top(getfield)(top(getfield)(f::TFFilter{Float64},:b)::Poly{Float64},:nzfirst)::Int64))::Int64)::Float64 # line 108:
        b = /(top(getfield)(f::TFFilter{Float64},:b)::Poly{Float64},k::Float64)::Poly{Float64} # line 109:
        z = convert($(Array{Complex{Float64},1}),roots(b::Poly{Float64})::Array{T,1})::Array{Complex{Float64},1} # line 110:
        p = convert($(Array{Complex{Float64},1}),roots(top(getfield)(f::TFFilter{Float64},:a)::Poly{Float64})::Array{T,1})::Array{Complex{Float64},1} # line 111:
        return $(Expr(:new, ZPKFilter{Complex{Float64},Complex{Float64},Float64}, :(z::Array{Complex{Float64},1}), :(p::Array{Complex{Float64},1}), :(k::Float64)))::ZPKFilter{Complex{Float64},Complex{Float64},Float64}
    end)))

@simonster
Copy link
Member Author

Reduced test case:

julia> f() = convert(Vector{Complex128}, AbstractArray[[1.0]][1]);

julia> f()
ERROR: no method convert(Type{Array{Complex{Float64},1}}, Array{Float64,1})
 in f at none:1

This fails both before and after 6002358 (and all the way back to at least 0.2). The reason git bisect picked out 6002358 is that type inference for roots(Poly{Float64}) now gives a less specific return type (AbstractArray{T,N} instead of Array{T,1}), which seems to have exposed this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants