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

Subtype relationships not detected with certain cases of Tuple{T,T} #20130

Open
TotalVerb opened this issue Jan 19, 2017 · 9 comments
Open

Subtype relationships not detected with certain cases of Tuple{T,T} #20130

TotalVerb opened this issue Jan 19, 2017 · 9 comments
Labels
domain:types and dispatch Types, subtyping and method dispatch

Comments

@TotalVerb
Copy link
Contributor

TotalVerb commented Jan 19, 2017

Given

julia> immutable X{T}
       end

julia> (Tuple{T} where T <: X) <: (Tuple{X{T}} where T)
true  # as expected

julia> (Tuple{T,T} where T <: X) <: (Tuple{X{T},X{T}} where T)
false # expected true

Given

julia> immutable Y{T,U}
       end

julia> A = Tuple{T,T} where T <: Y
Tuple{T,T} where T<:Y

julia> B = Tuple{Y{T,U} where U, Y{T,U} where U} where T
Tuple{Y{T,U} where U,Y{T,U} where U} where T

julia> A <: B
false  # expected true

(the following observation was incorrect)

julia> typeintersect(A, B) == A
true   # shouldn't this imply A <: B? [ edit: never mind, my mistake ]
@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 19, 2017

julia> (Tuple{T,T} where T <: X) <: (Tuple{X{T},X{T}} where T)
false # expected true

this is correct. Tuple{Union{}, Union{}} is a subtype of the left, but not of the right

julia> typeintersect(A, B) == A
true   # shouldn't this imply A <: B?

no, typeintersect can choose to return any type that is wider than the actual intersection. A valid answer thus is always A (even if there is no actual intersection).

@TotalVerb
Copy link
Contributor Author

I am reopening this issue because seems that Tuple{Union{}, Union{}} does not invalidate the subtype relationship

julia> (Tuple{Union{},Union{}}) <: (Tuple{X{T},X{T}} where T)
true

julia> (Tuple{Union{},Union{}}) <: (Tuple{T,T} where T <: X)
true

@TotalVerb TotalVerb reopened this Jan 19, 2017
@JeffBezanson
Copy link
Sponsor Member

Yes, I think we could eventually make <: return true in those cases. @vtjnash is right about typeintersect though.

@andyferris
Copy link
Member

andyferris commented Jan 19, 2017

Tuple{Union{}, Union{}} is a subtype of the left, but not of the right

So... we're not going to end up with method ambiguity errors when one doesn't deal with the (im)possibility of slots being Union{} across different methods, are we?

@Keno
Copy link
Member

Keno commented Jan 20, 2017

Union{} is going to cause a whole lot of ambiguity errors. Most of the time it doesn't matter though, because you rarely ever have those as a type parameter (any you can't construct an actual instance of it). We'll need a version of detect_ambiguities that ignores these though (I have one in some PR somewhere).

@tkelman
Copy link
Contributor

tkelman commented Jan 20, 2017

#20006 which needs rebasing to just be the last couple commits - we should probably change the default there, since the test that used to be verifying base was ambiguity-free is (hopefully temporarily) disabled

@JeffBezanson
Copy link
Sponsor Member

@andyferris No; type intersection treats Tuple{..., Union{}, ...} the same as Union{}.

@andyferris
Copy link
Member

OK, thanks for the clarification (phew!)

@gbaraldi
Copy link
Member

Tuple{Union{}} can no longer be constructed, so can we close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

7 participants