Skip to content

Return type of transparent inline macro lost/not inferred when macro expansion gets source position #7460

@TomasMikula

Description

@TomasMikula

Describe the bug

Scala version: 3.7.0

object Main extends App {
  val x = Macros.foo
  val y = Macros.bar

  x.substring(2, 4) // works as expected
  y.substring(2, 4) // compiles, but no IDE suggestions

  println(y)
}

There are IDE suggestions for x, but no suggestions for y (see screenshots below).

The only difference between the macros foo and bar is that bar accesses the position of macro expansion:

import scala.quoted.*

object Macros {

  transparent inline def foo: String =
    ${ fooImpl }

  private def fooImpl(using Quotes): Expr[String] =
    Expr("foo...")

  transparent inline def bar: String =
    ${ barImpl }

  private def barImpl(using Quotes): Expr[String] =
    quotes.reflect.Position.ofMacroExpansion.sourceFile.getJPath.get // this line is the culprit
    Expr("bar...")

}

Good (type of x is known to be String):

Image

Bad (type of y is unknown):

Image

Expected behavior

Mere access to source position in macro expansion should not break the IDE experience.

Operating system

macOS

Editor/Extension

VS Code

Version of Metals

1.50.0

Extra context or search terms

No response

Metadata

Metadata

Assignees

Labels

Scala 3Generic ticket relating to Scala 3bugSomething that is making a piece of functionality unusablepresentation-compilerSomething relating to the presentation compiler

Type

No type

Projects

Status

Triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions