-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add quotes test for some erased parameters APIs
- Loading branch information
1 parent
f22ac2f
commit faea51f
Showing
4 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
method <init>: () isGiven=false isImplicit=false erasedArgs=List() | ||
method m1: (i: scala.Int) isGiven=true isImplicit=false erasedArgs=List(false) | ||
method m2: (i: scala.Int) isGiven=false isImplicit=false erasedArgs=List(true) | ||
method m3: (i: scala.Int, j: scala.Int) isGiven=false isImplicit=false erasedArgs=List(false, true) | ||
method m4: (i: EC) isGiven=false isImplicit=false erasedArgs=List(true) | ||
val l1: scala.ContextFunction1[scala.Int, scala.Int] | ||
val l2: scala.compiletime.ErasedFunction with apply: (x$0: scala.Int @scala.annotation.internal.ErasedParam) isImplicit=false erasedParams=List(true) | ||
val l3: scala.compiletime.ErasedFunction with apply: (x$0: scala.Int @scala.annotation.internal.ErasedParam) isImplicit=true erasedParams=List(true) | ||
val l4: scala.compiletime.ErasedFunction with apply: (x$0: scala.Int, x$1: scala.Int @scala.annotation.internal.ErasedParam) isImplicit=false erasedParams=List(false, true) | ||
val l5: scala.compiletime.ErasedFunction with apply: (x$0: EC @scala.annotation.internal.ErasedParam) isImplicit=false erasedParams=List(true) |
35 changes: 35 additions & 0 deletions
35
tests/run-custom-args/erased/quotes-reflection/Macros_1.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import scala.quoted.* | ||
|
||
inline def inspect[A]: String = | ||
${ inspect2[A] } | ||
|
||
def inspect2[A: Type](using Quotes): Expr[String] = { | ||
import quotes.reflect.* | ||
|
||
val methods = TypeRepr.of[A].typeSymbol.declarations | ||
val names = methods.map { m => | ||
m.tree match | ||
case dd @ DefDef(name, params, r, body) => | ||
val paramStr = | ||
params.map { | ||
case ps: TermParamClause => | ||
val params = ps.params.map(p => s"${p.name}: ${p.tpt.show}").mkString("(", ", ", ")") | ||
s"$params isGiven=${ps.isGiven} isImplicit=${ps.isImplicit} erasedArgs=${ps.erasedArgs}" | ||
case ps: TypeParamClause => ps.params.map(_.show).mkString("[", ", ", "]") | ||
}.mkString("") | ||
s"method $name: $paramStr" | ||
case vd @ ValDef(name, tpt, body) => | ||
tpt.tpe match | ||
case Refinement(parent, "apply", tpe: MethodType) if parent == defn.ErasedFunctionClass.typeRef => | ||
assert(tpt.tpe.isErasedFunctionType) | ||
|
||
val params = tpe.paramNames.zip(tpe.paramTypes).map((n, t) => s"$n: ${t.show}").mkString("(", ", ", ")") | ||
s"val $name: ${parent.show} with apply: ${params} isImplicit=${tpe.isImplicit} erasedParams=${tpe.erasedParams}" | ||
case _ => | ||
s"val $name: ${tpt.show}" | ||
case td @ TypeDef(name, tpt) => s"type $name: ${tpt.show}" | ||
case _ => s"something else: $m" | ||
} | ||
|
||
Expr(names.mkString("\n")) | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/run-custom-args/erased/quotes-reflection/Test_2.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import scala.language.experimental.erasedDefinitions | ||
|
||
erased class EC | ||
|
||
trait X { | ||
def m1(using i: Int): Int | ||
def m2(erased i: Int): Int | ||
def m3(i: Int, erased j: Int): Int | ||
def m4(i: EC): Int | ||
|
||
val l1 = (x: Int) ?=> 5 | ||
val l2 = (erased x: Int) => 5 | ||
val l3 = (erased x: Int) ?=> 5 | ||
val l4 = (x: Int, erased y: Int) => 5 | ||
val l5 = (x: EC) => 5 | ||
} | ||
|
||
@main def Test = { | ||
println(inspect[X]) | ||
} |