@@ -76,16 +76,29 @@ class ElimByName extends MiniPhaseTransform with InfoTransformer { thisTransform
7676 cpy.Apply (tree)(tree.fun, args1)
7777 }
7878
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 ) =
8081 (symd is Param ) || (symd is (ParamAccessor , butNot = Method ))
8182
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 ]))
8587 tree.select(defn.Function0_apply ).appliedToNone
8688 else tree
8789 }
8890
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+
89102 def elimByNameParams (tp : Type )(implicit ctx : Context ): Type = tp match {
90103 case tp : PolyType =>
91104 tp.derivedPolyType(tp.paramNames, tp.paramBounds, elimByNameParams(tp.resultType))
@@ -102,6 +115,6 @@ class ElimByName extends MiniPhaseTransform with InfoTransformer { thisTransform
102115 }
103116
104117 def transformInfo (tp : Type , sym : Symbol )(implicit ctx : Context ): Type =
105- if (becomesFunction (sym)) transformParamInfo(tp)
118+ if (exprBecomesFunction (sym)) transformParamInfo(tp)
106119 else elimByNameParams(tp)
107120}
0 commit comments