Skip to content

-Ymagic-offset-header does not affect quotes.reflect.Position.ofMacroExpansion #24300

@lihaoyi

Description

@lihaoyi

Compiler version

3.7.4-RC3

Minimized code

lihaoyi scala3$ bin/scala -Ymagic-offset-header:MAGIC
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 generate: Int = ${ lineImpl }
     | 
def lineImpl(using x$1: scala.quoted.Quotes): scala.quoted.Expr[Int]
def generate: Int

scala> {
     | 
     | 
     | ///MAGIC:build.sbt
     | def foo = generate
     | def bar = ???
     | println(foo)
     | bar
     | }
5
scala.NotImplementedError: an implementation is missing
  at scala.Predef$.$qmark$qmark$qmark(Predef.scala:344)
  at rs$line$12$.bar(rs$line$12:2)
  ... 30 elided

See how println(foo) prints out 5, because the line is not offset by ///MAGIC:build.sbt, even though bar causes a stack trace with line number :2 because it is properly offset

Expectation

I would expect quotes.reflect.Position.ofMacroExpansion to reflect the -Ymagic-offset-header, just like compile errors and runtime bytecode locations do

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions