scalacenter/bloop

Bloop server has different behavior with sbt in macro

Closed this issue · 1 comments

Hi there,

I tried some macro code in my project below:

// macro
import scala.language.experimental.macros
import scala.reflect.macros.blackbox

object ConvertTransform {
  def convert(fn: => Any): String = macro convertImpl

  def convertImpl(c: blackbox.Context)(fn: c.Tree): c.Tree = {
    import c.universe._
  
    val pos = fn.pos
    val res = new String(pos.source.content).slice(pos.start, pos.end)
  
    Literal(Constant(res))
  }
}

and

// test code
object ConverterTester extends App {
  val codeStr = ConvertTransform.convert {
    10 + 20 + 30
  }
  println(codeStr)
}

Then I run my code in metals(version: 1.0.0) with Bloop 1.5.6, I can get correct result "10 + 20 + 30".
But if I run my code in sbt(version: 1.6.2), I get a different string "+ 20 +", which means the first expression and last expression is not captured.

So my question is why I get different behavior in bloop and sbt system.

Could you give a hint please what was wrong? Thanks 🙏