-
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.
Allow nested Quotes with a different owners
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`.
- Loading branch information
1 parent
c041327
commit 28ea733
Showing
5 changed files
with
36 additions
and
0 deletions.
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
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.* | ||
|
||
inline def checked2[A](inline n: A): A = | ||
${ checkedImpl2[A]('{n}) } | ||
|
||
private def checkedImpl2[A](n: Expr[A])(using Quotes, Type[A]): Expr[A] = | ||
import quotes.reflect.* | ||
val tree: Term = n.asTerm | ||
val acc = new TreeMap: | ||
override def transformTerm(tree: Term)(owner: Symbol): Term = | ||
tree match | ||
case Apply(Select(x, "*"), List(y)) => | ||
given Quotes = owner.toQuotes | ||
'{ | ||
val xt = ${x.asExprOf[Long]} | ||
xt | ||
}.asTerm | ||
case _ => | ||
super.transformTerm(tree)(owner) | ||
acc.transformTerm(tree)(Symbol.spliceOwner).asExprOf[A] |
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,6 @@ | ||
def test = { | ||
val u = 3L | ||
checked2(List(1L, 2L).map { k => | ||
u * 2L | ||
}) | ||
} |