-
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 documentation on Repeated and RepeatedParamClass
Close #18784
- Loading branch information
1 parent
c0eae68
commit aa2b565
Showing
3 changed files
with
52 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,20 @@ | ||
import scala.quoted.* | ||
|
||
object Macro { | ||
inline def repeated = ${Macro.repeatedImpl} | ||
def repeatedImpl(using Quotes):Expr[List[Int]] = { | ||
import quotes.reflect.* | ||
val args = List(Expr(1), Expr(2)) | ||
val listObjectTerm = '{ List }.asTerm | ||
Apply( | ||
TypeApply( | ||
Select.unique(listObjectTerm, "apply"), | ||
List(TypeTree.of[Int]) | ||
), | ||
List( | ||
Typed( | ||
Repeated(args.map(_.asTerm), TypeTree.of[Int]), | ||
Inferred(defn.RepeatedParamClass.typeRef.appliedTo(TypeRepr.of[Int])))) | ||
).asExprOf[List[Int]] | ||
} | ||
} |
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,2 @@ | ||
def Test: Unit = | ||
Macro.repeated |