oracle / truffleruby

A high performance implementation of the Ruby programming language, built on GraalVM.
https://www.graalvm.org/ruby/
Other
3k stars 183 forks source link

[interop] invokeMember should throw ArityException, not ArgumentError #1864

Open fniephaus opened 4 years ago

fniephaus commented 4 years ago

invokeMember should throw an ArityException in case the number of arguments is incorrect. At the moment, it throws a TruffleRuby-internal ArgumentError instead.

$ polyglot --jvm --shell
rGraalVM MultiLanguage Shell 19.3.0
Copyright (c) 2013-2019, Oracle and/or its affiliates
  Ruby version 2.6.2
ruby> Truffle::Interop.invoke([], :+)
wrong number of arguments (given 0, expected 1) (ArgumentError)
        at <ruby> <top (required)>(resource:/truffleruby/core/truffle/boot.rb:16:15-45)
        at <ruby> parsing-request(Unknown)

js> Polyglot.eval('python', '[]').append()
TypeError: append() missing 1 required positional argument: a
js> Polyglot.eval('ruby', '[]').delete()
wrong number of arguments (given 0, expected 1) (ArgumentError)
eregon commented 4 years ago

This is going to be a little bit tricky because the arity check must happen inside the method per Ruby semantics. So we'll have to translate ArgumentError to ArityException, but ideally only for "wrong number of arguments" ArgumentErrors, because the user could just raise ArgumentError, "message" which probably shouldn't become ArityException.

Translate ArgumentError to ArityException would be a good first step though.