diff --git a/compiler/src/dotty/tools/dotc/ast/Positioned.scala b/compiler/src/dotty/tools/dotc/ast/Positioned.scala index 5475935ba918..23d01371d174 100644 --- a/compiler/src/dotty/tools/dotc/ast/Positioned.scala +++ b/compiler/src/dotty/tools/dotc/ast/Positioned.scala @@ -55,11 +55,11 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src def sourcePos(using Context): SourcePosition = val info = WrappedSourceFile.locateMagicHeader(source) info match - case HasHeader(offset, originalFile) => - if span.start >= offset then // This span is in user code + // This span is in user code + case HasHeader(offset, originalFile) + if span.exists && span.start >= offset => originalFile.atSpan(span.shift(-offset)) - else // Otherwise, return the source position in the wrapper code - source.atSpan(span) + // Otherwise, return the source position in the wrapper code case _ => source.atSpan(span) /** This positioned item, widened to `SrcPos`. Used to make clear we only need the