@@ -76,16 +76,29 @@ class ElimByName extends MiniPhaseTransform with InfoTransformer { thisTransform
76
76
cpy.Apply (tree)(tree.fun, args1)
77
77
}
78
78
79
- private def becomesFunction (symd : SymDenotation )(implicit ctx : Context ) =
79
+ /** If denotation had an ExprType before, it now gets a function type */
80
+ private def exprBecomesFunction (symd : SymDenotation )(implicit ctx : Context ) =
80
81
(symd is Param ) || (symd is (ParamAccessor , butNot = Method ))
81
82
82
- override def transformIdent (tree : Ident )(implicit ctx : Context , info : TransformerInfo ): Tree = {
83
- val origDenot = originalDenotation(tree)
84
- if (becomesFunction(origDenot) && (origDenot.info.isInstanceOf [ExprType ]))
83
+ /** Map `tree` to `tree.apply()` is `ftree` was of ExprType and becomes now a function */
84
+ private def applyIfFunction (tree : Tree , ftree : Tree )(implicit ctx : Context ) = {
85
+ val origDenot = originalDenotation(ftree)
86
+ if (exprBecomesFunction(origDenot) && (origDenot.info.isInstanceOf [ExprType ]))
85
87
tree.select(defn.Function0_apply ).appliedToNone
86
88
else tree
87
89
}
88
90
91
+ override def transformIdent (tree : Ident )(implicit ctx : Context , info : TransformerInfo ): Tree =
92
+ applyIfFunction(tree, tree)
93
+
94
+ override def transformTypeApply (tree : TypeApply )(implicit ctx : Context , info : TransformerInfo ): Tree = tree match {
95
+ case TypeApply (Select (_, nme.asInstanceOf_), arg :: Nil ) =>
96
+ // tree might be of form e.asInstanceOf[x.type] where x becomes a function.
97
+ // See pos/t296.scala
98
+ applyIfFunction(tree, arg)
99
+ case _ => tree
100
+ }
101
+
89
102
def elimByNameParams (tp : Type )(implicit ctx : Context ): Type = tp match {
90
103
case tp : PolyType =>
91
104
tp.derivedPolyType(tp.paramNames, tp.paramBounds, elimByNameParams(tp.resultType))
@@ -102,6 +115,6 @@ class ElimByName extends MiniPhaseTransform with InfoTransformer { thisTransform
102
115
}
103
116
104
117
def transformInfo (tp : Type , sym : Symbol )(implicit ctx : Context ): Type =
105
- if (becomesFunction (sym)) transformParamInfo(tp)
118
+ if (exprBecomesFunction (sym)) transformParamInfo(tp)
106
119
else elimByNameParams(tp)
107
120
}
0 commit comments