Closed
Description
Compiler version
3.3.0, 3.3.1-RC4
Minimized code
// Macro.scala
package test
import scala.quoted.*
object Macro:
transparent inline def getType[T] =
${ getTypeImpl[T] }
private def getTypeImpl[T: Type](using Quotes): Expr[Any] =
import quotes.reflect.*
val tpe = TypeRepr.of[T]
val reprShow = tpe.show
tpe.asType match
case '[t] =>
val typeShow = TypeRepr.of[t].show
Expr((reprShow, typeShow))
// Aux.scala
package test
opaque type Id = Long
object Task:
opaque type Title = String
def run =
println((Macro.getType[Id], Macro.getType[Task.Title]))
// console
test.run
Output
((test.Aux$package.Id,scala.Long),(test.Task.Title,test.Task.Title))
Expectation
((test.Aux$package.Id,test.Aux$package.Id),(test.Task.Title,test.Task.Title))
I do expect to have the opaque type preserved in all situations.
I still haven't managed to catch the exact conditions when it fails (not sure that "same level" is to blame). Here's another situation where the behavior doesn't match the expectation:
package test
opaque type Id = Long
object Task:
opaque type Title = String
def run =
println((Macro.getType[Id], Macro.getType[Title]))
Output:
((test.Aux$package.Id,test.Aux$package.Id),(test.Task.Title,java.lang.String))
And with this run
it has expected result:
println((Macro.getType[Id], Macro.getType[Task.Title])) // Task.Title is better qualified