-
-
Notifications
You must be signed in to change notification settings - Fork 920
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
Line number in runtime warnings is one greater than the actual line number #1446
Comments
The warning line numbers do seem to be off by one. I put your example into a simple script with each expression on its own line, to see what you happen with JRuby and MRI:
JRuby
2.1.0 MRI
It seems that JRuby's warning line number is one greater than it should be. A very simple, but probably quite dodgy solution would be below. diff --git a/core/src/main/java/org/jruby/common/RubyWarnings.java b/core/src/main/java/org/jruby/common/RubyWarnings.java
index bb18271..689fc07 100644
--- a/core/src/main/java/org/jruby/common/RubyWarnings.java
+++ b/core/src/main/java/org/jruby/common/RubyWarnings.java
@@ -97,7 +97,7 @@ public class RubyWarnings implements IRubyWarnings, WarnCallback {
line = -1;
} else {
file = stack[0].getFileName();
- line = stack[0].getLineNumber();
+ line = stack[0].getLineNumber() - 1;
}
warn(id, file, line, message); Would need to look further into how the stack trace is built up behind the scenes here, rather than just adjust the line number back down by 1 where it is reported like the above snippet does. |
…warnings is one greater than the actual line number.
… of the actual line number. This fixes issue jruby#1446.
Hello @eldritchideen. Actually the stack trace was generated properly and the line number was totally fine up until the moment it got converted into a string. I fixed the issue in pull request #1450. |
Closing since I think PR #1450 fixed this. Re-open if I am mistaken. |
@enebo, you are correct. Thanks! |
… of the actual line number. This fixes issue jruby#1446.
There was still a couple of failing tests for line numbers. I've fixed them now a7c82e9. The build is still failing but I don't think it has anything to do with line numbers any more. |
I have been trying to fix the warnings that happen when I run JRuby tests and I noticed that when JRuby prints a typical runtime warning it always reports the wrong line number. The reported line number is always one greater than the actual line number.
Here is an example of the bad behavior:
In the example above, everything is on line 1, but the warning indicates line 2. I would expect JRuby to print "-e:1" but instead it prints "-e:2".
In contrast, the warning from MRI reports indicates line 1:
The reason I call
puts
in these examples is to make it totally clear that the code that produces the warning is entirely contained within line 1.I think this bug will make it harder to debug JRuby warnings, especially for new programmers. Time will be wasted looking at the wrong line.
The text was updated successfully, but these errors were encountered: