4
4
5
5
const Bottom = Union ()
6
6
7
+ function testintersect (a, b, result, cmp= is)
8
+ @test cmp (typeintersect (a, b), result)
9
+ @test cmp (typeintersect (b, a), result)
10
+ end
11
+ isnot (x,y) = ! is (x,y)
12
+
7
13
# basic type relationships
8
14
@test Int8 <: Integer
9
15
@test Int32 <: Integer
@@ -23,96 +29,96 @@ const Bottom = Union()
23
29
@test Array{Int8,1 } <: Array{Int8,1}
24
30
@test ! (Type{Bottom} <: Type{Int32} )
25
31
@test ! (Vector{Float64} <: Vector{Union(Float64,Float32)} )
26
- @test is (Bottom, typeintersect ( Vector{Float64},Vector{Union (Float64,Float32)}) )
32
+ testintersect ( Vector{Float64}, Vector{Union (Float64,Float32)}, Bottom )
27
33
28
34
@test ! isa (Array,Type{Any})
29
35
@test Type{Complex} <: DataType
30
36
@test isa (Complex,Type{Complex})
31
37
@test ! (Type{Ptr{Bottom}} <: Type{Ptr} )
32
38
@test ! (Type{Rational{Int}} <: Type{Rational} )
33
39
let T = TypeVar (:T ,true )
34
- @test ! is (Bottom, typeintersect ( Array{Bottom},AbstractArray{T}) )
35
- @test is (Bottom, typeintersect (Tuple{Type{Ptr{UInt8}},Ptr{Bottom}},
36
- Tuple{Type{Ptr{T}},Ptr{T}}) )
40
+ testintersect ( Array{Bottom},AbstractArray{T}, Bottom, isnot )
41
+ testintersect (Tuple{Type{Ptr{UInt8}},Ptr{Bottom}},
42
+ Tuple{Type{Ptr{T}},Ptr{T}}, Bottom )
37
43
@test ! (Type{T} <: TypeVar )
38
44
39
- @test isequal ( typeintersect ( Tuple{Range{Int},Tuple{Int,Int}},Tuple{AbstractArray{T},Dims}) ,
45
+ testintersect ( Tuple{Range{Int},Tuple{Int,Int}},Tuple{AbstractArray{T},Dims},
40
46
Tuple{Range{Int},Tuple{Int,Int}})
41
47
42
- @test isequal ( typeintersect ( Tuple{T, AbstractArray{T}}, Tuple{Number, Array{Int,1 }}) ,
48
+ testintersect ( Tuple{T, AbstractArray{T}}, Tuple{Number, Array{Int,1 }},
43
49
Tuple{Int, Array{Int,1 }})
44
50
45
- @test isequal ( typeintersect ( Tuple{T, AbstractArray{T}}, Tuple{Int, Array{Number,1 }}) ,
51
+ testintersect ( Tuple{T, AbstractArray{T}}, Tuple{Int, Array{Number,1 }},
46
52
Tuple{Int, Array{Number,1 }})
47
53
48
- @test isequal ( typeintersect ( Tuple{T, AbstractArray{T}},Tuple{Any, Array{Number,1 }}) ,
49
- Tuple{Number, Array{Number,1 }})
50
- @test ! is (Bottom, typeintersect ( Tuple{Array{T}, Array{T}}, Tuple{Array, Array{Any}}) )
54
+ testintersect ( Tuple{T, AbstractArray{T}},Tuple{Any, Array{Number,1 }},
55
+ Tuple{Number, Array{Number,1 }}, isequal )
56
+ testintersect ( Tuple{Array{T}, Array{T}}, Tuple{Array, Array{Any}}, Bottom, isnot )
51
57
f47 {T} (x:: Vector{Vector{T}} ) = 0
52
58
@test_throws MethodError f47 (Array (Vector,0 ))
53
59
@test f47 (Array (Vector{Int},0 )) == 0
54
- @test typeintersect (Tuple{T,T}, Tuple{Union (Float64,Int64),Int64}) == Tuple{Int64,Int64}
55
- @test typeintersect (Tuple{T,T}, Tuple{Int64,Union (Float64,Int64)}) == Tuple{Int64,Int64}
60
+ testintersect (Tuple{T,T}, Tuple{Union (Float64,Int64),Int64}, Tuple{Int64,Int64})
61
+ testintersect (Tuple{T,T}, Tuple{Int64,Union (Float64,Int64)}, Tuple{Int64,Int64})
56
62
57
63
TT = TypeVar (:T )
58
64
S = TypeVar (:S ,true ); N = TypeVar (:N ,true ); SN = TypeVar (:S ,Number,true )
59
- @test typeintersect (Type{TypeVar (:T ,Array{TT,1 })},Type{Array{SN,N}}) == Type{Array{SN,1 }}
65
+ testintersect (Type{TypeVar (:T ,Array{TT,1 })},Type{Array{SN,N}}, Type{Array{SN,1 }})
60
66
# issue #5359
61
- @test typeintersect (Tuple{Type{Array{T,1 }},Array{T,1 }},
62
- Tuple{Type{AbstractVector},Vector{Int}}) === Bottom
67
+ testintersect (Tuple{Type{Array{T,1 }},Array{T,1 }},
68
+ Tuple{Type{AbstractVector},Vector{Int}}, Bottom)
63
69
# issue #5559
64
- @test typeintersect (Tuple{Type{Vector{Complex128}}, AbstractVector},
65
- Tuple{Type{Array{T,N}}, Array{S,N}}) == Tuple{Type{Vector{Complex128}},Vector}
66
- @test typeintersect (Tuple{Type{Vector{Complex128}}, AbstractArray},
67
- Tuple{Type{Array{T,N}}, Array{S,N}}) == Tuple{Type{Vector{Complex128}},Vector}
70
+ testintersect (Tuple{Type{Vector{Complex128}}, AbstractVector},
71
+ Tuple{Type{Array{T,N}}, Array{S,N}}, Tuple{Type{Vector{Complex128}},Vector}, isequal)
72
+ testintersect (Tuple{Type{Vector{Complex128}}, AbstractArray},
73
+ Tuple{Type{Array{T,N}}, Array{S,N}}, Tuple{Type{Vector{Complex128}},Vector}, isequal)
68
74
69
- @test typeintersect (Type{Array{T}}, Type{AbstractArray{T}}) === Bottom
75
+ testintersect (Type{Array{T}}, Type{AbstractArray{T}}, Bottom)
70
76
71
- @test typeintersect (Type{Tuple{Bool,Vararg{Int}}}, Type{Tuple{Vararg{T}}}) === Bottom
72
- @test typeintersect (Type{Tuple{Bool,Vararg{Int}}}, Type{Tuple{T,Vararg{T}}}) === Bottom
77
+ testintersect (Type{Tuple{Bool,Vararg{Int}}}, Type{Tuple{Vararg{T}}}, Bottom)
78
+ testintersect (Type{Tuple{Bool,Vararg{Int}}}, Type{Tuple{T,Vararg{T}}}, Bottom)
73
79
74
- @test typeintersect (Tuple{Rational{T},T}, Tuple{Rational{Integer},Int}) === Tuple{Rational{Integer},Int}
80
+ testintersect (Tuple{Rational{T},T}, Tuple{Rational{Integer},Int}, Tuple{Rational{Integer},Int})
75
81
76
- @test typeintersect (Pair{T,Ptr{T}}, Pair{Ptr{S},S}) === Bottom
77
- @test typeintersect (Tuple{T,Ptr{T}}, Tuple{Ptr{S},S}) === Bottom
82
+ testintersect (Pair{T,Ptr{T}}, Pair{Ptr{S},S}, Bottom)
83
+ testintersect (Tuple{T,Ptr{T}}, Tuple{Ptr{S},S}, Bottom)
78
84
end
79
85
let N = TypeVar (:N ,true )
80
- @test isequal ( typeintersect (Tuple{NTuple{N,Integer},NTuple{N,Integer}},
81
- Tuple{Tuple{Integer,Integer}, Tuple{Vararg{Integer}}}) ,
86
+ testintersect (Tuple{NTuple{N,Integer},NTuple{N,Integer}},
87
+ Tuple{Tuple{Integer,Integer}, Tuple{Vararg{Integer}}},
82
88
Tuple{Tuple{Integer,Integer}, Tuple{Integer,Integer}})
83
- @test isequal ( typeintersect (Tuple{NTuple{N,Integer},NTuple{N,Integer}},
84
- Tuple{Tuple{Vararg{Integer}}, Tuple{Integer,Integer}}) ,
89
+ testintersect (Tuple{NTuple{N,Integer},NTuple{N,Integer}},
90
+ Tuple{Tuple{Vararg{Integer}}, Tuple{Integer,Integer}},
85
91
Tuple{Tuple{Integer,Integer}, Tuple{Integer,Integer}})
86
92
local A = typeintersect (Tuple{NTuple{N,Any},Array{Int,N}},
87
93
Tuple{Tuple{Int,Vararg{Int}},Array})
88
94
local B = Tuple{Tuple{Int,Vararg{Int}},Array{Int,N}}
89
95
@test A<: B && B<: A
90
- @test isequal ( typeintersect (Tuple{NTuple{N,Any},Array{Int,N}},
91
- Tuple{Tuple{Int,Vararg{Int}},Array{Int,2 }}) ,
96
+ testintersect (Tuple{NTuple{N,Any},Array{Int,N}},
97
+ Tuple{Tuple{Int,Vararg{Int}},Array{Int,2 }},
92
98
Tuple{Tuple{Int,Int}, Array{Int,2 }})
93
99
end
94
- @test is (Bottom, typeintersect ( Type{Any},Type{Complex}) )
95
- @test is (Bottom, typeintersect ( Type{Any},Type{TypeVar (:T ,Real)}) )
100
+ testintersect ( Type{Any},Type{Complex}, Bottom )
101
+ testintersect ( Type{Any},Type{TypeVar (:T ,Real)}, Bottom )
96
102
@test ! (Type{Array{Integer}} <: Type{AbstractArray{Integer}} )
97
103
@test ! (Type{Array{Integer}} <: Type{Array{TypeVar(:T,Integer)}} )
98
- @test is (Bottom, typeintersect ( Type{Function},UnionType) )
99
- @test is (Type{Int32}, typeintersect ( Type{Int32},DataType) )
104
+ testintersect ( Type{Function},UnionType,Bottom )
105
+ testintersect (Type{Int32}, DataType, Type{Int32})
100
106
@test ! (Type <: TypeVar )
101
- @test ! is (Bottom, typeintersect ( DataType, Type) )
102
- @test ! is (Bottom, typeintersect ( UnionType, Type) )
103
- @test ! is (Bottom, typeintersect ( DataType, Type{Int}) )
104
- @test ! is (Bottom, typeintersect ( DataType, Type{TypeVar (:T ,Int)}) )
105
- @test ! is (Bottom, typeintersect ( DataType, Type{TypeVar (:T ,Integer)}) )
107
+ testintersect ( DataType, Type, Bottom, isnot )
108
+ testintersect ( UnionType, Type, Bottom, isnot )
109
+ testintersect ( DataType, Type{Int}, Bottom, isnot )
110
+ testintersect ( DataType, Type{TypeVar (:T ,Int)}, Bottom, isnot )
111
+ testintersect ( DataType, Type{TypeVar (:T ,Integer)}, Bottom, isnot )
106
112
107
- @test typeintersect (Tuple{Vararg{Int}}, Tuple{Vararg{Bool}}) === Tuple{}
108
- @test typeintersect (Type{Tuple{Vararg{Int}}}, Type{Tuple{Vararg{Bool}}}) === Bottom
109
- @test typeintersect (Tuple{Bool,Vararg{Int}}, Tuple{Vararg{Bool}}) === Tuple{Bool,}
113
+ testintersect (Tuple{Vararg{Int}}, Tuple{Vararg{Bool}}, Tuple{})
114
+ testintersect (Type{Tuple{Vararg{Int}}}, Type{Tuple{Vararg{Bool}}}, Bottom)
115
+ testintersect (Tuple{Bool,Vararg{Int}}, Tuple{Vararg{Bool}}, Tuple{Bool,})
110
116
111
117
let T = TypeVar (:T ,Union (Float32,Float64))
112
- @test typeintersect (AbstractArray, Matrix{T}) == Matrix{T}
118
+ testintersect (AbstractArray, Matrix{T}, Matrix{T})
113
119
end
114
120
let T = TypeVar (:T ,Union (Float32,Float64),true )
115
- @test typeintersect (AbstractArray, Matrix{T}) == Matrix{T}
121
+ testintersect (AbstractArray, Matrix{T}, Matrix{T})
116
122
end
117
123
118
124
@test isa (Int,Type{TypeVar (:T ,Number)})
146
152
147
153
# issue #2997
148
154
let T = TypeVar (:T ,Union (Float64,Array{Float64,1 }),true )
149
- @test typeintersect (T,Real) === Float64
155
+ testintersect (T,Real, Float64)
150
156
end
151
157
152
158
# join
@@ -1361,7 +1367,7 @@ abstract IT4805{N, T}
1361
1367
let
1362
1368
T = TypeVar (:T ,Int,true )
1363
1369
N = TypeVar (:N ,true )
1364
- @test typeintersect (Type{IT4805{1 ,T}}, Type{TypeVar (:_ ,IT4805{N,Int})}) != Bottom
1370
+ testintersect (Type{IT4805{1 ,T}}, Type{TypeVar (:_ ,IT4805{N,Int})}, Bottom, isnot)
1365
1371
end
1366
1372
1367
1373
let
@@ -2002,7 +2008,7 @@ abstract AbstractThing{T,N}
2002
2008
type ConcreteThing{T<: FloatingPoint ,N} <: AbstractThing{T,N}
2003
2009
end
2004
2010
2005
- @test typeintersect (AbstractThing{TypeVar (:T ,true ),2 }, ConcreteThing) == ConcreteThing{TypeVar (:T ,FloatingPoint),2 }
2011
+ testintersect (AbstractThing{TypeVar (:T ,true ),2 }, ConcreteThing, ConcreteThing{TypeVar (:T ,FloatingPoint),2 }, isequal)
2006
2012
2007
2013
# issue #8978
2008
2014
module I8978
@@ -2816,3 +2822,10 @@ g10995((1, 2))
2816
2822
# issue #11149
2817
2823
@noinline f11149 (a,b,args... ) = (a,b,args... )
2818
2824
@test f11149 (1 ,2 ,3 ) == invoke (f11149, Tuple{Int,Int,Int}, 1 ,2 ,3 )
2825
+
2826
+ # issue #11136
2827
+ type A11136 end
2828
+ type B11136 end
2829
+ let T = TypeVar (:T , true ), TB = TypeVar (:T , B11136, true )
2830
+ testintersect (Tuple{T, T}, Tuple{A11136, TB}, Bottom)
2831
+ end
0 commit comments