@@ -143,6 +143,53 @@ function showerror(io::IO, e::MethodError)
143
143
print (io, " \n Note the difference between 1d column vector [1,2,3] and 2d row vector [1 2 3]." )
144
144
print (io, " \n You can convert to a column vector with the vec() function." )
145
145
end
146
+
147
+ # Display up to three closest candidates
148
+ lines = Array ((IOBuffer, Int), 0 )
149
+ for method in methods (e. f)
150
+ n = length (e. args)
151
+ if n != length (method. sig)
152
+ continue
153
+ end
154
+ buf = IOBuffer ()
155
+ print (buf, " $(e. f. env. name) (" )
156
+ first = true
157
+ right_matches = 0
158
+ for (arg, sigtype) in zip (e. args, method. sig)
159
+ if first
160
+ first = false
161
+ else
162
+ print (buf, " , " )
163
+ end
164
+ if typeof (arg) <: sigtype
165
+ right_matches += 1
166
+ print (buf, " ::$(sigtype) " )
167
+ else
168
+ Base. with_output_color (:red , buf) do buf
169
+ print (buf, " ::$(sigtype) " )
170
+ end
171
+ end
172
+ end
173
+ if right_matches > 0
174
+ print (buf, " )" )
175
+ push! (lines, (buf, right_matches))
176
+ end
177
+ end
178
+ if length (lines) != 0
179
+ Base. with_output_color (:normal , io) do io
180
+ println (io, " \n Closest candidates are:" )
181
+ sort! (lines, by = x -> - x[2 ])
182
+ i = 0
183
+ for line in lines
184
+ if i >= 3
185
+ println (io, " ..." )
186
+ break
187
+ end
188
+ i += 1
189
+ println (io, takebuf_string (line[1 ]))
190
+ end
191
+ end
192
+ end
146
193
end
147
194
148
195
function show_trace_entry (io, fname, file, line, n)
0 commit comments