Skip to content

Conversation

@liufengyun
Copy link
Contributor

Given the following macro:

import scala.tasty._
import scala.quoted._

inline def foo(x: Int): Int = ${ fooImpl('x) }

def fooImpl(x: Expr[Int])(implicit refl: Reflection) = {
  import refl._
  import util._

  val t1 : Term = x.unseal
  let (t1) { v =>
    let ('{ "hello" }.unseal) { y =>
      Select.overloaded(v, ">", Nil, y :: Nil)
    }
  }.seal.cast[Int]
}

Without the change, we get an error message like the following:

1 |def test(x: Int) = foo(x)
  |                   ^^^^^^
  |An exception occurred while executing macro expansion
  |assertion failed: no overloads available for > on Int with targs: ; args: x of types rhsTpe$_$1(x); expectedType: ?.all alternatives: def >(x: Double): Boolean, def >(x: Float): Boolean, def >(x: Long): Boolean, def >(x: Int): Boolean, def >(x: Char): Boolean, def >(x: Short): Boolean, def >(x: Byte): Boolean

With the change, mysterious type rhsTpe$_$1(x) is replaced with the type String.

Without the change, we get an error message like the following:

```
1 |def test(x: Int) = foo(x)
  |                   ^^^^^^
  |An exception occurred while executing macro expansion
  |assertion failed: no overloads available for > on Int with targs: ; args: x of types rhsTpe$_$1(x); expectedType: ?.all alternatives: def >(x: Double): Boolean, def >(x: Float): Boolean, def >(x: Long): Boolean, def >(x: Int): Boolean, def >(x: Char): Boolean, def >(x: Short): Boolean, def >(x: Byte): Boolean
```

With the change, mysterious type `rhsTpe$_$1(x)` is replaced with the type `String`.
@nicolasstucki nicolasstucki merged commit 9413cc0 into scala:master May 29, 2019
@nicolasstucki nicolasstucki deleted the macro-debuggability branch May 29, 2019 11:08
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

Successfully merging this pull request may close these issues.

2 participants