Skip to content

Commit a7bbe58

Browse files
authored
Fix compiler crash with -Ymagic-offset-header (#24124)
Fixes #24091 Since `span.start` is only valid when `span.exists`, we just check that first before calling `span.start` and otherwise fall back to the default code path Haven't tested it, but from the stack trace it looks like it should fix the problem
2 parents 172687a + 55b470f commit a7bbe58

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src
5555
def sourcePos(using Context): SourcePosition =
5656
val info = WrappedSourceFile.locateMagicHeader(source)
5757
info match
58-
case HasHeader(offset, originalFile) =>
59-
if span.start >= offset then // This span is in user code
58+
// This span is in user code
59+
case HasHeader(offset, originalFile)
60+
if span.exists && span.start >= offset =>
6061
originalFile.atSpan(span.shift(-offset))
61-
else // Otherwise, return the source position in the wrapper code
62-
source.atSpan(span)
62+
// Otherwise, return the source position in the wrapper code
6363
case _ => source.atSpan(span)
6464

6565
/** This positioned item, widened to `SrcPos`. Used to make clear we only need the

0 commit comments

Comments
 (0)