@@ -34,7 +34,7 @@ function signature(m::Method)
34
34
35
35
def[:args ] = arguments (m)
36
36
def[:whereparams ] = where_parameters (m)
37
- def[:params ] = parameters (m)
37
+ def[:params ] = type_parameters (m)
38
38
def[:kwargs ] = kwargs (m)
39
39
40
40
return Dict (k => v for (k, v) in def if v != = nothing ) # filter out nonfields.
@@ -52,10 +52,10 @@ function argument_names(m::Method)
52
52
return arg_names
53
53
end
54
54
55
-
56
- function argument_types (m :: Method )
55
+ argument_types (m :: Method ) = argument_types (m . sig)
56
+ function argument_types (sig )
57
57
# First parameter of `sig` is the type of the function itself
58
- return parameters (m . sig)[2 : end ]
58
+ return parameters (sig)[2 : end ]
59
59
end
60
60
61
61
name_of_type (x) = x
@@ -74,7 +74,10 @@ function name_of_type(x::UnionAll)
74
74
whereparam = where_parameters (x. var)
75
75
return :($ name where $ whereparam)
76
76
end
77
-
77
+ function name_of_type (x:: Union )
78
+ parameter_names = name_of_type .(Base. uniontypes (x))
79
+ return :(Union{$ (parameter_names... )})
80
+ end
78
81
79
82
function arguments (m:: Method )
80
83
arg_names = argument_names (m)
@@ -96,28 +99,28 @@ function where_parameters(x::TypeVar)
96
99
if x. lb === Union{} && x. ub === Any
97
100
return x. name
98
101
elseif x. lb === Union{}
99
- return :($ (x. name) <: $ (Symbol (x. ub)))
102
+ return :($ (x. name) <: $ (name_of_type (x. ub)))
100
103
elseif x. ub === Any
101
- return :($ (x. name) >: $ (Symbol (x. lb)))
104
+ return :($ (x. name) >: $ (name_of_type (x. lb)))
102
105
else
103
- return :($ (Symbol (x. lb)) <: $ (x. name) <: $ (Symbol (x. ub)))
106
+ return :($ (name_of_type (x. lb)) <: $ (x. name) <: $ (name_of_type (x. ub)))
104
107
end
105
108
end
106
109
107
- function where_parameters (m:: Method )
108
- m . sig isa UnionAll || return nothing
109
-
110
+ where_parameters (m:: Method ) = where_parameters (m . sig )
111
+ where_parameters ( sig) = nothing
112
+ function where_parameters (sig :: UnionAll )
110
113
whereparams = []
111
- sig = m. sig
112
114
while sig isa UnionAll
113
115
push! (whereparams, where_parameters (sig. var))
114
116
sig = sig. body
115
117
end
116
118
return whereparams
117
119
end
118
120
119
- function parameters (m:: Method )
120
- typeof_type = first (parameters (m. sig)) # will be e.g Type{Foo{P}} if it has any parameters
121
+ type_parameters (m:: Method ) = type_parameters (m. sig)
122
+ function type_parameters (sig)
123
+ typeof_type = first (parameters (sig)) # will be e.g Type{Foo{P}} if it has any parameters
121
124
typeof_type <: Type{<:Any} || return nothing
122
125
123
126
function_type = first (parameters (typeof_type)) # will be e.g. Foo{P}
0 commit comments