Skip to content

Commit bbe61b7

Browse files
committed
prepare_extension_function works with multiple args
1 parent 83f7d0f commit bbe61b7

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

src/io.jl

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,30 @@ Base.showerror(io::IO, e::ExtensionLoadError) =
2323

2424
struct ExtensionMethodError <: Exception
2525
fn::Function
26-
x
26+
args::Tuple
2727
end
2828

2929

3030
function Base.showerror(io::IO, e::ExtensionMethodError)
3131
fname = String(nameof(e.fn))
32-
print(
33-
io,
34-
"ExtensionMethodError: no method matching " * fname * "(::" * String(nameof(typeof(e.x))) * ")\n"
35-
* "The function " * fname * " exists in a loaded extension, but no method is defined for this combination of argument types.\n"
36-
* "\n"
37-
* "Candidates are:\n"
32+
argtypes = typeof.(e.args)
33+
println(io,
34+
"ExtensionMethodError: no method matching " * fname
35+
* "(" * join(map(x-> "::"*String(nameof(x)),argtypes),',')
36+
* ")")
37+
println(io,"The function " * fname * " exists in a loaded extension,"
38+
*" but no method is defined for this combination of argument types.\n"
39+
* "\nCandidates are:\n"
3840
)
39-
return println.(io, filter(x -> x != which(e.fn, (typeof(e.x),)), methods(e.fn)))
41+
println.(io, filter(x -> x != which(e.fn, (argtypes...,)), methods(e.fn)))
42+
return nothing
4043
end
4144

42-
function prepare_extension_function(fname::Symbol, weakdeps::Vector{Symbol}, x::Symbol)
45+
function prepare_extension_function(fname::Symbol, weakdeps::Vector{Symbol}, args::Vector{Symbol})
4346
expr = quote
44-
function $fname($x; kwargs...)
45-
if mapreduce(x -> isdefined(Main, x), &, $weakdeps)
46-
throw(ExtensionMethodError($fname, $x))
47+
function $fname($(args...); kwargs...)
48+
if mapreduce(x -> isdefined(Main, x) && isa(getfield(Main,x),Module), &, $weakdeps)
49+
throw(ExtensionMethodError($fname, ($(args...),)))
4750
else
4851
throw(ExtensionLoadError(nameof($fname), $weakdeps))
4952
end
@@ -310,11 +313,12 @@ function simplexgrid(file::String, ::Type{Val{:sg}}; kwargs...)
310313
return g
311314
end
312315

313-
prepare_extension_function(:simplexgrid_from_gmsh, [:Gmsh], :filename)
316+
prepare_extension_function(:simplexgrid_from_gmsh, [:Gmsh], [:filename])
314317
# function simplexgrid_from_gmsh(filename; incomplete = false, Tc = Float32, Ti = Int32)
315318
# throw(ErrorException("Missing Gmsh extension. Add Gmsh.jl to your environment and import it to read msh or geo files."))
316319
# end
317320

321+
318322
function simplexgrid_to_gmsh end
319323

320324
function mixedgrid_from_gmsh end

0 commit comments

Comments
 (0)