Skip to content

Commit

Permalink
Backport "Avoid crashes on missing positions" to LTS (#20798)
Browse files Browse the repository at this point in the history
Backports #19250 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jun 26, 2024
2 parents 6d67f75 + 1cf11ec commit d4a1742
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler

given TreeMethods: TreeMethods with
extension (self: Tree)
def pos: Position = self.sourcePos
def pos: Position =
val treePos = self.sourcePos
if treePos.exists then treePos
else
if xCheckMacro then report.warning(s"Missing tree position (defaulting to position 0): ${Printer.TreeStructure.show(self)}\nThis is a compiler bug. Please report it.")
self.source.atSpan(dotc.util.Spans.Span(0))

def symbol: Symbol = self.symbol
def show(using printer: Printer[Tree]): String = printer.show(self)
def isExpr: Boolean =
Expand Down Expand Up @@ -2593,7 +2599,13 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def info: TypeRepr = self.denot.info

def pos: Option[Position] =
if self.exists then Some(self.sourcePos) else None
if self.exists then
val symPos = self.sourcePos
if symPos.exists then Some(symPos)
else
if xCheckMacro then report.warning(s"Missing symbol position (defaulting to position 0): $self\nThis is a compiler bug. Please report it.")
Some(self.source.atSpan(dotc.util.Spans.Span(0)))
else None

def docstring: Option[String] =
import dotc.core.Comments.CommentsContext
Expand Down

0 comments on commit d4a1742

Please sign in to comment.