@@ -15,10 +15,6 @@ import util.Attachment
15
15
import core .StdNames .nme
16
16
import ast .Trees ._
17
17
18
- object ElimByName {
19
- val ByNameArg = new Attachment .Key [Unit ]
20
- }
21
-
22
18
/** This phase eliminates ExprTypes `=> T` as types of function parameters, and replaces them by
23
19
* nullary function types. More precisely:
24
20
*
@@ -39,13 +35,15 @@ object ElimByName {
39
35
*
40
36
* This makes the argument compatible with a parameter type of () => T, which will be the
41
37
* formal parameter type at erasure. But to be -Ycheckable until then, any argument
42
- * ARG rewritten by the rules above is again wrapped in an application ARG.apply(),
43
- * labelled with a `ByNameParam` attachment. Erasure will later strip wrapped
44
- * `.apply()` calls with ByNameParam attachments.
38
+ * ARG rewritten by the rules above is again wrapped in an application DummyApply(ARG)
39
+ * where
40
+ *
41
+ * DummyApply: [T](() => T): T
42
+ *
43
+ * is a synthetic method defined in Definitions. Erasure will later strip these DummyApply wrappers.
45
44
*/
46
45
class ElimByName extends MiniPhaseTransform with InfoTransformer { thisTransformer =>
47
46
import ast .tpd ._
48
- import ElimByName ._
49
47
50
48
override def phaseName : String = " elimByName"
51
49
@@ -64,17 +62,16 @@ class ElimByName extends MiniPhaseTransform with InfoTransformer { thisTransform
64
62
65
63
def transformArg (arg : Tree , formal : Type ): Tree = formal.dealias match {
66
64
case formalExpr : ExprType =>
65
+ val argType = arg.tpe.widen
67
66
val argFun = arg match {
68
67
case Apply (Select (qual, nme.apply), Nil ) if qual.tpe derivesFrom defn.FunctionClass (0 ) =>
69
68
qual
70
69
case _ =>
71
70
val meth = ctx.newSymbol(
72
- ctx.owner, nme.ANON_FUN , Synthetic | Method , MethodType (Nil , Nil , arg.tpe.widen ))
71
+ ctx.owner, nme.ANON_FUN , Synthetic | Method , MethodType (Nil , Nil , argType ))
73
72
Closure (meth, _ => arg.changeOwner(ctx.owner, meth))
74
73
}
75
- val argApplied = argFun.select(defn.Function0_apply ).appliedToNone
76
- argApplied.putAttachment(ByNameArg , ())
77
- argApplied
74
+ ref(defn.dummyApply).appliedToType(argType).appliedTo(argFun)
78
75
case _ =>
79
76
arg
80
77
}
0 commit comments