Strict typing and restricting types in a method's signature

i came up with this ugliness, purely for the sake of learning

@generated function require(method, args...)
  t = Base.to_tuple_type(args)
  t = Tuple{method, t.parameters...}
  if ccall(:jl_method_exists, Cint, (Any, Any), method.name.mt, t) == 0
    :(error("$method is required"))
  end
end

function myfunc(a)
  require(feature, a)
  ...
end

i had to lift the body of the method_exist function from reflections.jl, because none of the exported functions take a function type as opposed to a function, understandably. it works as intended. i wonder if i butchered julia badly here, or it is actually something reasonable.

1 Like