Skip to content

Commit fd83074

Browse files
committed
Ignore invalid source sections for now
1 parent 174a25a commit fd83074

File tree

1 file changed

+17
-5
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler

1 file changed

+17
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/SourceMap.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,25 @@ private static int readNum(ByteArrayInputStream offsets) {
117117
}
118118

119119
public static SourceSection getSourceSection(Source source, int startLine, int startColumn, int endLine, int endColumn) {
120-
if (source == null || !source.hasCharacters()) {
120+
if (source == null) {
121121
return null;
122+
} else if (!source.hasCharacters()) {
123+
return source.createUnavailableSection();
124+
}
125+
try {
126+
/* Truffle columns are 1-based */
127+
startColumn = Math.max(startColumn + 1, 1);
128+
endColumn = Math.max(endColumn + 1, 1);
129+
/* Truffle doesn't consider the newline a part of the line */
130+
if (endColumn == source.getLineLength(endLine) + 1) {
131+
endColumn--;
132+
}
133+
return source.createSection(startLine, startColumn, endLine, endColumn);
134+
} catch (IllegalArgumentException e) {
135+
// TODO GR-40896 we don't track source ranges of f-strings correctly
136+
// Also consider sources created from ast module
137+
return source.createUnavailableSection();
122138
}
123-
/* Truffle columns are 1-based and it doesn't consider the newline a part of the line */
124-
startColumn = Math.max(startColumn + 1, 1);
125-
endColumn = Math.max(Math.min(endColumn + 1, source.getLineLength(endLine)), 1);
126-
return source.createSection(startLine, startColumn, endLine, endColumn);
127139
}
128140

129141
public SourceSection getSourceSection(Source source, int bci) {

0 commit comments

Comments
 (0)