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

fix #23685, incorrect empty intersection with identity convert method #23700

Merged
merged 1 commit into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1201,3 +1201,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