Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bloop server has different behavior with sbt in macro #2125

Closed
lyfne123 opened this issue Jul 25, 2023 · 1 comment
Closed

Bloop server has different behavior with sbt in macro #2125

lyfne123 opened this issue Jul 25, 2023 · 1 comment

Comments

@lyfne123
Copy link

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.

@hartmut27
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants