Skip to content

Commit

Permalink
juliatypes.jl: start fixing tests for diagonals
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
JeffBezanson committed Jan 23, 2015
1 parent fc61385 commit 6035402
Showing 1 changed file with 48 additions and 14 deletions.
62 changes: 48 additions & 14 deletions examples/juliatypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ end

function var_lt(b::Var, a::Union(Ty,Var), env)
bb = env.vars[b]
#println("$b($(bb.lb),$(bb.ub)) <: $a")
!bb.right && return issub(bb.ub, a, env) # check ∀b . b<:a
!issub(bb.lb, a, env) && return false
# for contravariance we would need to compute a meet here, but
Expand All @@ -363,6 +364,7 @@ end

function var_gt(b::Var, a::Union(Ty,Var), env)
bb = env.vars[b]
#println("$b($(bb.lb),$(bb.ub)) >: $a")
!bb.right && return issub(a, bb.lb, env) # check ∀b . b>:a
!issub(a, bb.ub, env) && return false
bb.lb = join(bb.lb, a, env)
Expand Down Expand Up @@ -557,6 +559,33 @@ function test_2()
@test !issub((Int, (Real, Integer)), (Int...))
end

function test_no_diagonal()
# from test_3
@test issub((@UnionAll T @UnionAll S tupletype(T,S)), (@UnionAll T tupletype(T,T)))

@test isequal_type((@UnionAll T tupletype(T,T)), (@UnionAll T @UnionAll S tupletype(T,S)))

@test issub(tupletype(inst(ArrayT,Ty(Integer),1), Ty(Int)),
(@UnionAll T<:Ty(Integer) tupletype(inst(ArrayT,T,1),T)))

@test issub(Ty((Int,String,Vector{Any})),
@UnionAll T tupletype(T, T, inst(ArrayT,T,1)))

@test isequal_type(Ty(Array{(Integer,Integer),1}),
inst(ArrayT, (@UnionAll T<:Ty(Integer) tupletype(T,T)), 1))

@test issub(Ty((Float32,Array{Real,1})),
@UnionAll T<:Ty(Real) @UnionAll S<:inst(AbstractArrayT,T,1) tupletype(T,S))

@test isequal_type((@UnionAll T tupletype(inst(RefT,T), T)),
(@UnionAll T @UnionAll S<:T tupletype(inst(RefT,T),S)))
@test isequal_type((@UnionAll T tupletype(inst(RefT,T), T)),
(@UnionAll T @UnionAll S<:T @UnionAll R<:S tupletype(inst(RefT,T),R)))

@test issub((@UnionAll S<:Ty(Int) (@UnionAll R<:Ty(String) tupletype(S,R,Ty(Vector{Any})))),
(@UnionAll T tupletype(T, T, inst(ArrayT,T,1))))
end

# level 3: UnionAll
function test_3()
@test issub_strict(Ty(Array{Int,1}), @UnionAll T inst(ArrayT, T, 1))
Expand All @@ -566,11 +595,9 @@ function test_3()

@test !issub((@UnionAll T<:Ty(Real) T), (@UnionAll T<:Ty(Integer) T))

@test issub((@UnionAll T tupletype(T,T)), (@UnionAll T @UnionAll S tupletype(T,S)))
@test issub((@UnionAll T @UnionAll S tupletype(T,S)), (@UnionAll T tupletype(T,T)))

@test isequal_type((@UnionAll T tupletype(T,T)), (@UnionAll T @UnionAll S tupletype(T,S)))
@test isequal_type((@UnionAll T @UnionAll S tupletype(T,S)), (@UnionAll T tupletype(T,T)))
@test issub_strict((@UnionAll T tupletype(T,T)), (@UnionAll T @UnionAll S tupletype(T,S)))
@test isequal_type((@UnionAll T tupletype(T,T)), (@UnionAll R tupletype(R,R)))
@test !issub(tupletype(Ty(Real),Ty(Real)), @UnionAll T<:Ty(Real) tupletype(T,T))

@test !issub((@UnionAll T<:Ty(Integer) @UnionAll S<:Ty(Number) (T,S)),
(@UnionAll T<:Ty(Integer) @UnionAll S<:Ty(Number) (S,T)))
Expand All @@ -593,8 +620,10 @@ function test_3()
@test isequal_type((@UnionAll T tupletype(T)), tupletype(AnyT))
@test isequal_type((@UnionAll T<:Ty(Real) tupletype(T)), tupletype(Ty(Real)))

@test issub(tupletype(inst(ArrayT,Ty(Integer),1), Ty(Int)),
@test !issub(tupletype(inst(ArrayT,Ty(Integer),1), Ty(Int)),
(@UnionAll T<:Ty(Integer) tupletype(inst(ArrayT,T,1),T)))
@test issub(tupletype(inst(ArrayT,Ty(Integer),1), Ty(Int)),
(@UnionAll T<:Ty(Integer) @UnionAll S<:T tupletype(inst(ArrayT,T,1),S)))

@test !issub(tupletype(inst(ArrayT,Ty(Integer),1), Ty(Real)),
(@UnionAll T<:Ty(Integer) tupletype(inst(ArrayT,T,1),T)))
Expand All @@ -606,14 +635,14 @@ function test_3()
@test !issub(Ty((Int,String,Vector{(Integer,)})),
@UnionAll T tupletype(T,T,inst(ArrayT,tupletype(T),1)))

@test issub(Ty((Int,String,Vector{Any})),
@test !issub(Ty((Int,String,Vector{Any})),
@UnionAll T tupletype(T, T, inst(ArrayT,T,1)))

@test isequal_type(Ty(Array{Int,1}), inst(ArrayT, (@UnionAll T<:Ty(Int) T), 1))
@test isequal_type(Ty(Array{(Any,),1}), inst(ArrayT, (@UnionAll T tupletype(T)), 1))

@test isequal_type(Ty(Array{(Integer,Integer),1}),
inst(ArrayT, (@UnionAll T<:Ty(Integer) tupletype(T,T)), 1))
@test isequal_type(Ty(Array{(Int,Int),1}),
inst(ArrayT, (@UnionAll T<:Ty(Int) tupletype(T,T)), 1))
@test !issub(Ty(Array{(Int,Integer),1}),
inst(ArrayT, (@UnionAll T<:Ty(Integer) tupletype(T,T)), 1))

Expand Down Expand Up @@ -642,8 +671,8 @@ function test_3()
@test !issub(Ty((Float32,Array{Float64,1})),
@UnionAll T<:Ty(Real) @UnionAll S<:inst(AbstractArrayT,T,1) tupletype(T,S))

@test issub(Ty((Float32,Array{Real,1})),
@UnionAll T<:Ty(Real) @UnionAll S<:inst(AbstractArrayT,T,1) tupletype(T,S))
@test !issub(Ty((Float32,Array{Real,1})),
@UnionAll T<:Ty(Real) @UnionAll S<:inst(AbstractArrayT,T,1) tupletype(T,S))

@test !issub(Ty((Number,Array{Real,1})),
@UnionAll T<:Ty(Real) @UnionAll S<:inst(AbstractArrayT,T,1) tupletype(T,S))
Expand All @@ -668,9 +697,9 @@ function test_3()
@test issub_strict((@UnionAll T @UnionAll S>:T inst(PairT,T,S)),
(@UnionAll T @UnionAll S inst(PairT,T,S)))

@test isequal_type((@UnionAll T tupletype(inst(RefT,T), T)),
@test issub_strict((@UnionAll T tupletype(inst(RefT,T), T)),
(@UnionAll T @UnionAll S<:T tupletype(inst(RefT,T),S)))
@test isequal_type((@UnionAll T tupletype(inst(RefT,T), T)),
@test issub_strict((@UnionAll T tupletype(inst(RefT,T), T)),
(@UnionAll T @UnionAll S<:T @UnionAll R<:S tupletype(inst(RefT,T),R)))
@test isequal_type((@UnionAll T tupletype(inst(RefT,T), T)),
(@UnionAll T @UnionAll T<:S<:T tupletype(inst(RefT,T),S)))
Expand Down Expand Up @@ -767,7 +796,7 @@ end

# tricky type variable lower bounds
function test_6()
@test issub((@UnionAll S<:Ty(Int) (@UnionAll R<:Ty(String) tupletype(S,R,Ty(Vector{Any})))),
@test !issub((@UnionAll S<:Ty(Int) (@UnionAll R<:Ty(String) tupletype(S,R,Ty(Vector{Any})))),
(@UnionAll T tupletype(T, T, inst(ArrayT,T,1))))

@test !issub((@UnionAll S<:Ty(Int) (@UnionAll R<:Ty(String) tupletype(S,R,Ty(Vector{Integer})))),
Expand Down Expand Up @@ -917,6 +946,11 @@ function test_properties()
if issubTS
for R in menagerie
if issub(S, R)
if !issub(T, R)
@show T
@show S
@show R
end
@test issub(T, R) # issub(S, R) → issub(T, R)
@test issub(inst(RefT,S), @UnionAll T<:U<:R inst(RefT,U))
end
Expand Down

0 comments on commit 6035402

Please sign in to comment.