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

Type being initiated with field not matching template type, rather being a "DataType" #11777

Closed
dlfivefifty opened this issue Jun 20, 2015 · 7 comments
Labels
regression Regression in behavior compared to a previous version types and dispatch Types, subtyping and method dispatch

Comments

@dlfivefifty
Copy link
Contributor

There's a strange bug that is causing segfaults and other behaviour in Julia 0.4 that's being triggered in ApproxFun. Sorry I haven't been able to narrow it down further but I reduced it to the following, where S.op is bizarrely a DataType instead of an instance of the type:

Pkg.checkout("ApproxFun","development")
using ApproxFun
import ApproxFun: SpaceOperator

m=MappedSpace(Ray(),Ultraspherical{1}())    
sp=MappedSpace(Ray(),JacobiWeight(0.,-1.,Ultraspherical{1}()))
C=Conversion(m.space,sp.space)
S=SpaceOperator(C,m,sp)
S.op|>typeof    # returns DataType instead of typeof(C)

The definition of SpaceOperator doesn't allow S.op to be a DataType:

immutable SpaceOperator{T,O<:Operator,S<:FunctionSpace,V<:FunctionSpace} <: BandedOperator{T}
    op::O
    domainspace::S
    rangespace::V
end

I believe the bug is triggered by an error in a Base.convert overrides, but even so, it shouldn't propagate like this.

@dlfivefifty
Copy link
Contributor Author

Explicitly stating the types doesn't fix the issue either:

SpaceOperator{Float64,typeof(C),typeof(m),typeof(sp)}(C,m,sp).op|>typeof  #returns DataType, not typeof(C)

@dlfivefifty
Copy link
Contributor Author

The trigger for the bug may be the following convert code:

function Base.convert{BT<:Operator}(::Type{BT},D::ConversionWrapper)
    BO=convert(BandedOperator{eltype(BT)},D.op)
    ConversionWrapper{typeof(BO),eltype(BT)}(BO)::BT
end

For some reason the type statement ::BT is not working, as @code_typed seems to think it is Union{}:

@code_typed convert(typeof(C),C)
...
    end::Union{}))))

@dlfivefifty
Copy link
Contributor Author

And after changing convert to be

function Base.convert{BT<:Operator}(::Type{BT},D::ConversionWrapper)
    BO=convert(BandedOperator{eltype(BT)},D.op)
    CW=ConversionWrapper{typeof(BO),eltype(BT)}(BO)
    CW
end

I get another strange bug:

julia> @code_typed convert(typeof(C),C)
1-element Array{Any,1}:
Error showing value of type Array{Any,1}:
ERROR: type Union has no field mutable
 in isbits at reflection.jl:67
 in show_delim_array at show.jl:162
 in show_vector at show.jl:1281
 in show at show.jl:1285
 in show_delim_array at show.jl:167
 in show_vector at show.jl:1281
 in show at show.jl:1285
 in show_delim_array at show.jl:167
 in show_vector at show.jl:1281
 in show at show.jl:1285
 in show_unquoted at ./show.jl:724
 in show_unquoted_quote_expr at show.jl:444
 in showcompact_lim at show.jl:93
 in sprint at iostream.jl:205
 in alignment at show.jl:924
 in alignment at show.jl:956
 in print_matrix at show.jl:1031
 in print_matrix at show.jl:1023
 in anonymous at replutil.jl:23
 in with_output_limit at ./show.jl:1231
 in writemime at replutil.jl:23
 in display at REPL.jl:113
 in display at REPL.jl:116
 in display at multimedia.jl:151
 in print_response at REPL.jl:133
 in print_response at REPL.jl:120
 in anonymous at REPL.jl:600
 in run_interface at ./LineEdit.jl:1566
 in run_frontend at ./REPL.jl:841
 in run_repl at ./REPL.jl:165
 in _start at ./client.jl:446

@yuyichao
Copy link
Contributor

@dlfivefifty Please quote the code when you post it here (I just editted them to include the quote) It's really hard to read when they are not quoted.

Judging from the Union{} I guess you are on master? The code_typed issue is probably a duplicate of #11590 and is fixed by #11600

@dlfivefifty
Copy link
Contributor Author

@yuyichao Sorry about that, I will do so in the future. Thanks for fixing it for me!

@JeffBezanson JeffBezanson added regression Regression in behavior compared to a previous version types and dispatch Types, subtyping and method dispatch labels Jun 22, 2015
@dlfivefifty
Copy link
Contributor Author

Adding the following line fixed this particular bug:

Base.convert{CW<:ConversionWrapper}(::Type{CW},D::CW)=D

Maybe I should just close the issue since it's too buried at the moment to be tracked down?

@dlfivefifty
Copy link
Contributor Author

This is caused by #11874

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Regression in behavior compared to a previous version types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

3 participants