FossilOrigin-Name: f49d9465e02a773fe8b1add8537291fd03620b1c6f14f3b0846a4aa4d362ee5f
private
alpha 2 years ago
parent 28b9fd32d0
commit fe7e902211

@ -141,10 +141,13 @@ module Lox
end end
def visit_call(expr) def visit_call(expr)
callee = evaluate(expr.callee) func = evaluate(expr.callee)
args = expr.args.map { evaluate(_1) } args = expr.args.map { evaluate(_1) }
callee.call(self, args) raise RuntimeError.new(expr.paren, "Can only call functions and classes.") unless func.respond_to?(:call)
raise RuntimeError.new(expr.paren, "Expected #{func.arity} arguments but got #{args.size}.") unless args.size == func.arity
func.call(self, args)
end end
private private

Loading…
Cancel
Save