Skip to content

Commit

Permalink
fix #23685, incorrect empty intersection with identity convert meth…
Browse files Browse the repository at this point in the history
…od (#23700)
  • Loading branch information
JeffBezanson authored Sep 14, 2017
1 parent 6153f97 commit 1001320
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,14 @@ static jl_value_t *intersect_invariant(jl_value_t *x, jl_value_t *y, jl_stenv_t
flip_vars(e);
return ii;
}
/*
TODO: This is a band-aid for issue #23685. A better solution would be to
first normalize types so that all `where` expressions in covariant position
are pulled out to the top level.
*/
if ((jl_is_typevar(x) && !jl_is_typevar(y) && lookup(e, (jl_tvar_t*)x) == NULL) ||
(jl_is_typevar(y) && !jl_is_typevar(x) && lookup(e, (jl_tvar_t*)y) == NULL))
return ii;
jl_value_t *root=NULL;
jl_savedenv_t se;
JL_GC_PUSH2(&ii, &root);
Expand Down
10 changes: 10 additions & 0 deletions test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1202,3 +1202,13 @@ g23024(TT::Tuple{DataType}) = f23024(TT[1], v23024)

@test !Core.Inference.isconstType(Type{typeof(Union{})}) # could be Core.TypeofBottom or Type{Union{}} at runtime
@test Base.return_types(supertype, (Type{typeof(Union{})},)) == Any[Any]

# issue #23685
struct Node23685{T}
end
@inline function update23685!(::Node23685{T}) where T
convert(Node23685{T}, Node23685{Float64}())
end
h23685 = Node23685{Float64}()
f23685() = update23685!(h23685)
@test f23685() === h23685
13 changes: 13 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ function test_3()
@test !issub(Tuple{Type{Vector{T}} where T, Vector{Float64}}, Tuple{Type{T}, T} where T)
@test !issub(Tuple{Vector{Float64}, Type{Vector{T}} where T}, Tuple{T, Type{T}} where T)
@test !issub(Tuple{Type{Ref{T}} where T, Vector{Float64}}, Tuple{Ref{T}, T} where T)

@test !issub(Tuple{Type{Ref{T}} where T, Ref{Float64}}, Tuple{Type{T},T} where T)
end

# level 4: Union
Expand Down Expand Up @@ -930,6 +932,17 @@ function test_intersection()
@testintersect(Tuple{Ref{Ref{T}} where T, Ref},
Tuple{Ref{T}, Ref{T}} where T,
Tuple{Ref{Ref{T}}, Ref{Ref{T}}} where T)

# issue #23685
@testintersect(Pair{Type{Z},Z} where Z,
Pair{Type{Ref{T}} where T, Ref{Float64}},
Bottom)
@testintersect(Tuple{Type{Z},Z} where Z,
Tuple{Type{Ref{T}} where T, Ref{Float64}},
!Bottom)
@test_broken typeintersect(Tuple{Type{Z},Z} where Z,
Tuple{Type{Ref{T}} where T, Ref{Float64}}) ==
Tuple{Type{Ref{Float64}},Ref{Float64}}
end

function test_intersection_properties()
Expand Down

0 comments on commit 1001320

Please sign in to comment.