Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c9d2f34

Browse files
authoredAug 23, 2019
Merge pull request #7085 from dotty-staging/cleanup-reflection-let
Cleanup implementation of Reflection.let
2 parents f0f8241 + 0846ca4 commit c9d2f34

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed
 

‎library/src-bootstrapped/scala/tasty/reflect/TreeUtils.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,15 @@ trait TreeUtils
287287
def let(rhs: Term)(body: Ident => Term): Term = {
288288
import scala.quoted.QuoteContext
289289
given as QuoteContext = new QuoteContext(this)
290-
type T // TODO probably it is better to use the Sealed contruct rather than let the user create their own existential type
291-
implicit val rhsTpe: quoted.Type[T] = rhs.tpe.seal.asInstanceOf[quoted.Type[T]]
292-
val rhsExpr = rhs.seal.cast[T]
293-
val expr = '{
294-
val x = $rhsExpr
295-
${
296-
val id = ('x).unseal.asInstanceOf[Ident]
297-
body(id).seal
298-
}
290+
val expr = (rhs.seal: @unchecked) match {
291+
case '{ $rhsExpr: $t } =>
292+
'{
293+
val x = $rhsExpr
294+
${
295+
val id = ('x).unseal.asInstanceOf[Ident]
296+
body(id).seal
297+
}
298+
}
299299
}
300300
expr.unseal
301301
}

‎tests/run-macros/tasty-unsafe-let/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import scala.quoted._
22

33
object Macros {
44

5-
inline def let[T](rhs: T)(body: => T => Unit): Unit =
5+
inline def let[T](rhs: => T)(body: => T => Unit): Unit =
66
${ impl('rhs, 'body) }
77

88
private def impl[T](rhs: Expr[T], body: Expr[T => Unit]) given (qctx: QuoteContext): Expr[Unit] = {

0 commit comments

Comments
 (0)
Please sign in to comment.