-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
checkArity confusingly raises line of outer caller for nested calls #5103
Comments
basically boils down to having some-form of static Java checks in a dynamic language (Ruby). as for the stack-trace could you please clarify what you mean. |
@kares yes, this does seem hard to get right. The thing is, it is a bad user experience at the moment because JRuby quite confidently tells you you have an args issue at a given line, when the problem is really somewhere else. I don't know if there is an efficient easy way to solve this. It would be nice if possible however. The current stack, roughly speaking, is RrubyMethod(A) -> JavaMethod(B) -> RubyMethodThatIncorrectlyImplementsJavaInterface(C). The error message today makes it seem like A is where the bug is, when the real problem is somewhere between B and C |
I feel like the real problem here is that we have no context for the failed call, because the dispatch logic for the Ruby-based interface impl doesn't insert any context. It's a sort of hidden method_missing dispatch happening under the covers, but since it's implemented in "native" code it doesn't show up in the Ruby trace. The dispatch logic here could perhaps be improved to provide a better error, perhaps something like "interface method SomeIfc.someMethod was not implemented in class SomeRubyClass". |
@headius that error message would have been amazing here :) |
It occurs to me there's a slight snag with my approach: we still need
What we might be able to do is create a new call site type specifically for interface dispatches that follows method_missing protocol:
Tricky but doable. |
A similar issue is documented in #6335. The case here is slightly different, since we are simply not defining the expected interface method on the generated class, but the basic cause (arity check happens during call plumbing and not inside the method) is the same. |
Jitted code handles arity-checking differently than in the interpreter. Where the interpreter always pushed a backtrace element before the arity check, the JVM does the arity-check in a separately-generated varargs wrapper (if the method is specific- arity) or before setting a line number (if the method is variable- arity). This has the effect of either omitting the error frame altogether (specific) or having the line number be -1 (variable). This commit makes the following modifications to allow the arity error line to be shown in jitted code: * Set the current line number immediately upon creating the method so that it is set in the JVM before the arity check. * Process jitted method names with the varargs marker if they were not preceded by the actual method body. The varargs-marked method can only appear on its own or immediately after the real jitted method body. This fixes all known cases where the argument error line is omitted or not set properly in the JVM trace. In addition, this patch moves the management of the current line number into the IRBytecodeAdapter, rather than maintaining it in the JVMVisitor instance. Fixes jruby#6335. This may also improve the case described in jruby#5103, since all JVM frames will have proper line numbers at the point of error.
Environment
Provide at least:
Expected Behavior
I have code something like:
Actual Behavior
JRuby generates an
ArgumentError: wrong number of arguments (1 for 2)
that points to the line insomeOtherMethod
, when the real error is that we implemented the interface incorrectly. The stack trace shouldn't filter out the java in this case, but do the full stack trace to expose this.The text was updated successfully, but these errors were encountered: