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)
9292 return def
9393end
9494
95-
96-
9795function slot_names (m:: Method )
9896 ci = Base. uncompressed_ast (m)
9997 return ci. slotnames
10098end
10199
102100function argument_names (m:: Method )
103101 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]
106104 return arg_names
107105end
108106
Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ function only_method(f, typ=Tuple{Vararg{Any}})
4242 return first (ms)
4343end
4444
45+ struct TestCallableStruct end
46+ (self:: TestCallableStruct )(x) = 2 x
47+ (self:: TestCallableStruct )(x:: T ,y:: R ) where {T,R} = 2 x + y
48+
4549@testset " method.jl: signature" begin
4650 @testset " Basics" begin
4751 @test_signature basic1 (x) = 2 x
112116 @test_signature ((:: T ) where T) -> 0 # Anonymous parameter
113117 end
114118
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+
115129 @testset " vararg" begin
116130 @test_signature f17 (xs:: Vararg{Any, N} where N) = 2
117131
You can’t perform that action at this time.
0 commit comments