File tree 3 files changed +16
-1
lines changed
compiler/src/dotty/tools/dotc/typer 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1446,7 +1446,9 @@ trait Applications extends Compatibility {
1446
1446
unapplyArgType
1447
1447
1448
1448
val dummyArg = dummyTreeOfType(ownType)
1449
- val unapplyApp = typedExpr(untpd.TypedSplice (Apply (unapplyFn, dummyArg :: Nil )))
1449
+ val unapplyApp = withMode(Mode .NoInline ) { // transparent inline unapplies are exapnded when indexing the pattern see `indexPattern` in Typer.
1450
+ typedExpr(untpd.TypedSplice (Apply (unapplyFn, dummyArg :: Nil )))
1451
+ }
1450
1452
def unapplyImplicits (unapp : Tree ): List [Tree ] = {
1451
1453
val res = List .newBuilder[Tree ]
1452
1454
def loop (unapp : Tree ): Unit = unapp match {
Original file line number Diff line number Diff line change
1
+ import scala .quoted ._
2
+
3
+ object Unapplier :
4
+ transparent inline def unapply (arg : Any ): Option [Int ] = $ {unapplyImpl(' arg )}
5
+
6
+ def unapplyImpl (using Quotes )(argExpr : Expr [Any ]): Expr [Option [Int ]] =
7
+ executionCount += 1
8
+ assert(executionCount == 1 , " macro should only expand once" )
9
+ ' {Some (1 )}
10
+
11
+ private var executionCount = 0
Original file line number Diff line number Diff line change
1
+ @ main def main () =
2
+ val Unapplier (result) = Some (5 )
You can’t perform that action at this time.
0 commit comments