Skip to content

Commit 5aca3a1

Browse files
eregonandrykonchin
authored andcommitted
Ensure we never use (0,0) SourceSections
* Those would appear in the debugger as going back to the first line, which is incorrect and confusing.
1 parent e78023f commit 5aca3a1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/main/java/org/truffleruby/language/RubyNode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ public void unsafeSetSourceSection(SourceSection sourceSection) {
106106
public void unsafeSetSourceSection(int charIndex, int sourceLength) {
107107
assert !hasSource();
108108

109+
// The only valid case for a (0,0) SourceSection is the RootNode SourceSection of eval("").
110+
// We handle that case specially by using an unavailable SourceSection, so then every (0,0) is a bug.
111+
assert !(sourceLength == 0 && charIndex == 0);
112+
109113
setSourceCharIndex(charIndex);
110114
setSourceLength(sourceLength);
111115
}

src/main/java/org/truffleruby/parser/YARPTranslatorDriver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
177177

178178
var node = parseResult.value;
179179

180-
final SourceSection sourceSection = source.createSection(0, rubySource.getBytes().length);
180+
final SourceSection sourceSection = rubySource.getBytes().length == 0
181+
? source.createUnavailableSection()
182+
: source.createSection(0, rubySource.getBytes().length);
181183
final SourceIndexLength sourceIndexLength = SourceIndexLength.fromSourceSection(sourceSection);
182184

183185
final String modulePath = staticLexicalScope == null || staticLexicalScope == context.getRootLexicalScope()

0 commit comments

Comments
 (0)