@@ -4,14 +4,16 @@ package transform
4
4
5
5
import core ._
6
6
import Flags ._
7
- import MegaPhase ._
7
+ import MegaPhase ._ , DenotTransformers . IdentityDenotTransformer
8
8
import Symbols ._ , Contexts ._ , Types ._ , Decorators ._
9
9
import StdNames .nme
10
10
import ast .Trees ._
11
11
import ast .TreeTypeMap
12
12
13
13
/** Rewrite applications `<byname>(...)` to context closures `() ?=> ...` */
14
- class ByNameLambda extends MiniPhase :
14
+ class ByNameLambda extends MiniPhase , IdentityDenotTransformer :
15
+ thisPhase =>
16
+
15
17
import ast .tpd ._
16
18
17
19
def phaseName : String = ByNameLambda .name
@@ -22,18 +24,18 @@ class ByNameLambda extends MiniPhase:
22
24
case Apply (Select (fn, nme.apply), Nil ) if isPurePath(fn) && fn.tpe.widen.isByName =>
23
25
fn
24
26
case _ =>
25
- ByNameLambda (body)
27
+ byNameClosure (body)
26
28
case _ => app
27
29
30
+ def byNameClosure (body : Tree )(using Context ): Block =
31
+ val restpe = body.tpe.widenIfUnstable.deskolemized
32
+ val meth = newAnonFun(ctx.owner, MethodType (Nil , restpe), coord = body.span)
33
+ Closure (meth, _ => body.changeOwnerAfter(ctx.owner, meth, thisPhase),
34
+ targetType = defn.ContextFunction0 .typeRef.appliedTo(restpe))
35
+
28
36
object ByNameLambda :
29
37
import ast .tpd ._
30
38
31
39
val name = " byNameLambda"
32
40
33
- def apply (body : Tree )(using Context ): Block =
34
- val restpe = body.tpe.widenIfUnstable.deskolemized
35
- val meth = newAnonFun(ctx.owner, MethodType (Nil , restpe), coord = body.span)
36
- Closure (meth, _ => body.changeOwner(ctx.owner, meth),
37
- targetType = defn.ContextFunction0 .typeRef.appliedTo(restpe))
38
-
39
41
end ByNameLambda
0 commit comments