@@ -57,6 +57,7 @@ class Erasure extends Phase with DenotTransformer {
5757 case _ => false
5858 }
5959 }
60+
6061 def erasedName =
6162 if ref.is(Flags .Method )
6263 && contextResultsAreErased(ref.symbol)
@@ -383,8 +384,8 @@ object Erasure {
383384 case _ : FunProto | AnyFunctionProto => tree
384385 case _ => tree.tpe.widen match
385386 case mt : MethodType if tree.isTerm =>
386- if mt.paramInfos.isEmpty then adaptToType(tree.appliedToNone, pt )
387- else etaExpand (tree, mt , pt)
387+ assert( mt.paramInfos.isEmpty)
388+ adaptToType (tree.appliedToNone , pt)
388389 case tpw =>
389390 if (pt.isInstanceOf [ProtoType ] || tree.tpe <:< pt)
390391 tree
@@ -533,61 +534,6 @@ object Erasure {
533534 else
534535 tree
535536 end adaptClosure
536-
537- /** Eta expand given `tree` that has the given method type `mt`, so that
538- * it conforms to erased result type `pt`.
539- * To do this correctly, we have to look at the tree's original pre-erasure
540- * type and figure out which context function types in its result are
541- * not yet instantiated.
542- */
543- def etaExpand (tree : Tree , mt : MethodType , pt : Type )(using Context ): Tree =
544- report.log(i " eta expanding $tree" )
545- val defs = new mutable.ListBuffer [Tree ]
546- val tree1 = LiftErased .liftApp(defs, tree)
547- val xmt = if tree.isInstanceOf [Apply ] then mt else expandedMethodType(mt, tree)
548- val targetLength = xmt.paramInfos.length
549- val origOwner = ctx.owner
550-
551- // The original type from which closures should be constructed
552- val origType = contextFunctionResultTypeCovering(tree.symbol, targetLength)
553-
554- def abstracted (args : List [Tree ], tp : Type , pt : Type )(using Context ): Tree =
555- if args.length < targetLength then
556- try
557- val defn .ContextFunctionType (argTpes, resTpe, isErased) = tp : @ unchecked
558- if isErased then abstracted(args, resTpe, pt)
559- else
560- val anonFun = newSymbol(
561- ctx.owner, nme.ANON_FUN , Flags .Synthetic | Flags .Method ,
562- MethodType (argTpes, resTpe), coord = tree.span.endPos)
563- anonFun.info = transformInfo(anonFun, anonFun.info)
564- def lambdaBody (refss : List [List [Tree ]]) =
565- val refs :: Nil = refss : @ unchecked
566- val expandedRefs = refs.map(_.withSpan(tree.span.endPos)) match
567- case (bunchedParam @ Ident (nme.ALLARGS )) :: Nil =>
568- argTpes.indices.toList.map(n =>
569- bunchedParam
570- .select(nme.primitive.arrayApply)
571- .appliedTo(Literal (Constant (n))))
572- case refs1 => refs1
573- abstracted(args ::: expandedRefs, resTpe, anonFun.info.finalResultType)(
574- using ctx.withOwner(anonFun))
575-
576- val unadapted = Closure (anonFun, lambdaBody)
577- cpy.Block (unadapted)(unadapted.stats, adaptClosure(unadapted.expr.asInstanceOf [Closure ]))
578- catch case ex : MatchError =>
579- println(i " error while abstracting tree = $tree | mt = $mt | args = $args%, % | tp = $tp | pt = $pt" )
580- throw ex
581- else
582- assert(args.length == targetLength, i " wrong # args tree = $tree | args = $args%, % | mt = $mt | tree type = ${tree.tpe}" )
583- val app = untpd.cpy.Apply (tree1)(tree1, args)
584- assert(ctx.typer.isInstanceOf [Erasure .Typer ])
585- ctx.typer.typed(app, pt)
586- .changeOwnerAfter(origOwner, ctx.owner, erasurePhase.asInstanceOf [Erasure ])
587-
588- seq(defs.toList, abstracted(Nil , origType, pt))
589- end etaExpand
590-
591537 end Boxing
592538
593539 class Typer (erasurePhase : DenotTransformer ) extends typer.ReTyper with NoChecking {
0 commit comments