Skip to content

Commit d20dd28

Browse files
authored
Make quotes.reflect.Position.ofMacroExpansion consider -Ymagic-offset-header (#24301)
Fixes #24300 Tested manually with the reproduction in the original ticket, seems that `quotes.reflect.Position.ofMacroExpansion.startLine` and `.sourceFile` now correctly considers the `///MAGIC:build.sbt` comment ```scala lihaoyi scala3$ bin/scala -Ymagic-offset-header:MAGIC The `--offline` option is experimental Please bear in mind that non-ideal user experience should be expected. If you encounter any bugs or have feedback to share, make sure to reach out to the maintenance team at https://github.com/VirtusLab/scala-cli Welcome to Scala 3.8.0-RC1-bin-SNAPSHOT-git-840804f (17.0.14, Java OpenJDK 64-Bit Server VM). Type in expressions for evaluation. Or try :help. scala> import scala.quoted.* | def lineImpl(using Quotes): Expr[Int] = { | val sourceFile = quotes.reflect.Position.ofMacroExpansion.sourceFile | val line = quotes.reflect.Position.ofMacroExpansion.startLine + 1 | Expr(line) | } | inline implicit def line: Int = ${ lineImpl } | | def fileImpl(using Quotes): Expr[String] = { | import quotes.reflect._ | Expr(quotes.reflect.Position.ofMacroExpansion.sourceFile.path) | } | | inline implicit def file: String = ${ fileImpl } def lineImpl(using x$1: scala.quoted.Quotes): scala.quoted.Expr[Int] def line: Int def fileImpl(using x$1: scala.quoted.Quotes): scala.quoted.Expr[String] def file: String scala> { | | | ///MAGIC:build.sbt | println(file) | println(line) | def bar = ??? | bar | } build.sbt 1 scala.NotImplementedError: an implementation is missing at scala.Predef$.$qmark$qmark$qmark(Predef.scala:344) at rs$line$3$.bar(rs$line$3:2) ... 32 elided ```
1 parent 389483e commit d20dd28

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

compiler/src/dotty/tools/dotc/quoted/MacroExpansion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ object MacroExpansion {
1313
ctx.property(MacroExpansionPosition)
1414

1515
def context(inlinedFrom: tpd.Tree)(using Context): Context =
16-
QuotesCache.init(ctx.fresh).setProperty(MacroExpansionPosition, SourcePosition(inlinedFrom.source, inlinedFrom.span)).setTypeAssigner(new Typer(ctx.nestingLevel + 1)).withSource(inlinedFrom.source)
16+
QuotesCache.init(ctx.fresh).setProperty(MacroExpansionPosition, inlinedFrom.sourcePos).setTypeAssigner(new Typer(ctx.nestingLevel + 1)).withSource(inlinedFrom.source)
1717
}
1818

0 commit comments

Comments
 (0)