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

diagonal dispatch type-inference error #11015

Closed
vtjnash opened this issue Apr 26, 2015 · 1 comment
Closed

diagonal dispatch type-inference error #11015

vtjnash opened this issue Apr 26, 2015 · 1 comment
Assignees
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request types and dispatch Types, subtyping and method dispatch
Milestone

Comments

@vtjnash
Copy link
Member

vtjnash commented Apr 26, 2015

I noticed the following discrepancy while attempting to enable inline_incompletematch_allowed:

julia> Base._methods(convert, (Type{TypeVar(:_,Union(Bool,Function))}, Bool), 1)
1-element Array{Any,1}:
 svec(Tuple{Type{Bool},Bool},svec(),convert(::Type{Bool},x::Bool) at bool.jl:3)

julia> Base._methods(convert, (Type{TypeVar(:_,Union(Bool,Function))}, Bool), -1)
3-element Array{Any,1}:
 svec(Tuple{Type{Bool},Bool},svec(),convert(::Type{Bool},x::Bool) at bool.jl:3)    
 svec(Tuple{Type{Bool},Bool},svec(),convert(::Type{Bool},x::Real) at bool.jl:4)    
 svec(Tuple{Type{Bool},Bool},svec(T,Bool),convert{T}(::Type{T},x::T) at base.jl:38) # this method is missing from the above list

this can trigger a fault in inference given the following method definitions:

julia> type AT
         f::Union(Bool,Function)
       end

julia> g{S}(::Type{S}, ::S) = Int64(1)
g (generic function with 1 method)

julia> f(a::AT) = g(Base.fieldtype(typeof(a), :f), true)
f (generic function with 1 method)

julia> g(::Type{Bool}, ::Bool) = 2.0
g (generic function with 2 methods)

julia> code_typed(f,(AT,))
1-element Array{Any,1}:
 :($(Expr(:lambda, Any[:a], Any[Any[],Any[Any[:a,AT,0]],Any[],Any[]], :(begin  # none, line 1:
        return g(((top(getfield))(Base,:fieldtype))(typeof(a::AT)::Type{AT},:f)::Type{_<:Union(Bool,Function)},true)::Float64
    end::Float64))))

julia> f(AT(true))
5.0e-324
#oops: should be 1 but got `reinterpret(Float64,Int64(1))`

(note that g(fieldtype, x) is a derived from the lowered form of a field-assignment, so this situation is actually fairly plausible to create in practice)`

@vtjnash
Copy link
Member Author

vtjnash commented Sep 15, 2016

I assume this will be covered by #8974 in v0.6?

@StefanKarpinski StefanKarpinski added help wanted Indicates that a maintainer wants help on an issue or pull request and removed help wanted Indicates that a maintainer wants help on an issue or pull request labels Oct 27, 2016
JeffBezanson added a commit that referenced this issue Jan 25, 2017
add a test for #11015, diagonal dispatch inference error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Indicates that a maintainer wants help on an issue or pull request types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

3 participants