diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index ef2eacf42225..22be293c3562 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -2698,9 +2698,10 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler if self.exists then val symPos = self.sourcePos if symPos.exists then Some(symPos) - else + else if self.source.exists then 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 else None def docstring: Option[String] = diff --git a/tests/pos-macros/i21672/Macro_1.scala b/tests/pos-macros/i21672/Macro_1.scala new file mode 100644 index 000000000000..2e17631d6cf4 --- /dev/null +++ b/tests/pos-macros/i21672/Macro_1.scala @@ -0,0 +1,10 @@ +object Repro { + inline def apply(): Unit = ${ applyImpl } + + import scala.quoted.* + def applyImpl(using q: Quotes): Expr[Unit] = { + import q.reflect.* + report.info(TypeRepr.of[Some[String]].typeSymbol.pos.toString) + '{ () } + } +} diff --git a/tests/pos-macros/i21672/Test_2.scala b/tests/pos-macros/i21672/Test_2.scala new file mode 100644 index 000000000000..b164962100af --- /dev/null +++ b/tests/pos-macros/i21672/Test_2.scala @@ -0,0 +1,3 @@ +//> using options -Xfatal-warnings +object Test: + Repro()