@@ -3,6 +3,7 @@ package dotc
33package transform
44
55import core ._
6+ import Flags ._
67import MegaPhase ._
78import Symbols ._ , Contexts ._ , Types ._ , Decorators ._
89import StdNames .nme
@@ -46,38 +47,34 @@ class BetaReduce extends MiniPhase:
4647 fn match
4748 case Typed (expr, _) => betaReduce(tree, expr, args)
4849 case Block (Nil , expr) => betaReduce(tree, expr, args)
49- case Block ((anonFun : DefDef ) :: Nil , closure : Closure ) => BetaReduce (tree)( anonFun, args, true )
50+ case Block ((anonFun : DefDef ) :: Nil , closure : Closure ) => BetaReduce (anonFun, args)
5051 case _ => tree
5152
5253object BetaReduce :
5354 import ast .tpd ._
5455
5556 /** Beta-reduces a call to `ddef` with arguments `argSyms` */
56- def apply (tree : Tree )( ddef : DefDef , args : List [Tree ], noBindings : Boolean )(using ctx : Context ) =
57+ def apply (ddef : DefDef , args : List [Tree ])(using ctx : Context ) =
5758 val bindings = List .newBuilder[ValDef ]
5859 val vparams = ddef.vparamss.iterator.flatten.toList
60+ assert(args.hasSameLengthAs(vparams))
5961 val argSyms =
6062 for (arg, param) <- args.zip(vparams) yield
6163 arg.tpe.dealias match
6264 case ref @ TermRef (NoPrefix , _) if isPurePath(arg) =>
6365 ref.symbol
6466 case _ =>
65- if noBindings then // TODO always generate bindings
66- NoSymbol
67- else
68- val binding = SyntheticValDef (param.name, arg)
69- bindings += binding
70- binding.symbol
67+ val flags = Synthetic | (param.symbol.flags & Erased )
68+ val binding = ValDef (ctx.newSymbol(ctx.owner, param.name, flags, arg.tpe.widen, coord = arg.span), arg)
69+ bindings += binding
70+ binding.symbol
7171
72- if argSyms.forall(_.exists) && argSyms.hasSameLengthAs(vparams) then // TODO assert rather than fail silently
73- seq(
74- bindings.result(),
75- TreeTypeMap (
76- oldOwners = ddef.symbol :: Nil ,
77- newOwners = ctx.owner :: Nil ,
78- substFrom = vparams.map(_.symbol),
79- substTo = argSyms
80- ).transform(ddef.rhs)
81- )
82- else
83- tree
72+ val expansion = TreeTypeMap (
73+ oldOwners = ddef.symbol :: Nil ,
74+ newOwners = ctx.owner :: Nil ,
75+ substFrom = vparams.map(_.symbol),
76+ substTo = argSyms
77+ ).transform(ddef.rhs)
78+
79+ seq(bindings.result(), expansion)
80+ end apply
0 commit comments