File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -92,17 +92,15 @@ function signature(orig_sig::Type{<:Tuple}; extra_hygiene=false)
92
92
return def
93
93
end
94
94
95
-
96
-
97
95
function slot_names (m:: Method )
98
96
ci = Base. uncompressed_ast (m)
99
97
return ci. slotnames
100
98
end
101
99
102
100
function argument_names (m:: Method )
103
101
slot_syms = slot_names (m)
104
- @assert slot_syms[ 1 ] === Symbol ( " #self#" )
105
- arg_names = slot_syms[2 : m. nargs] # nargs includes 1 for `#self#`
102
+ # nargs includes 1 for ` #self#` or the function object name;
103
+ arg_names = slot_syms[2 : m. nargs]
106
104
return arg_names
107
105
end
108
106
Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ function only_method(f, typ=Tuple{Vararg{Any}})
42
42
return first (ms)
43
43
end
44
44
45
+ struct TestCallableStruct end
46
+ (self:: TestCallableStruct )(x) = 2 x
47
+ (self:: TestCallableStruct )(x:: T ,y:: R ) where {T,R} = 2 x + y
48
+
45
49
@testset " method.jl: signature" begin
46
50
@testset " Basics" begin
47
51
@test_signature basic1 (x) = 2 x
112
116
@test_signature ((:: T ) where T) -> 0 # Anonymous parameter
113
117
end
114
118
119
+ @testset " callable structs" begin
120
+ ms = collect (methods (TestCallableStruct ()))
121
+ sig1 = signature (first (filter (m -> m. nargs == 2 , ms)))
122
+ @test sig1[:name ] == :TestCallableStruct
123
+ @test sig1[:args ] == [:x ]
124
+ sig2 = signature (first (filter (m -> m. nargs == 3 , ms)))
125
+ @test sig2[:name ] == :TestCallableStruct
126
+ @test sig2[:args ] == Expr[:(x:: T ),:(y:: R )]
127
+ end
128
+
115
129
@testset " vararg" begin
116
130
@test_signature f17 (xs:: Vararg{Any, N} where N) = 2
117
131
You can’t perform that action at this time.
0 commit comments