@@ -3,6 +3,7 @@ package dotc
3
3
package transform
4
4
5
5
import core ._
6
+ import Flags ._
6
7
import MegaPhase ._
7
8
import Symbols ._ , Contexts ._ , Types ._ , Decorators ._
8
9
import StdNames .nme
@@ -46,38 +47,34 @@ class BetaReduce extends MiniPhase:
46
47
fn match
47
48
case Typed (expr, _) => betaReduce(tree, expr, args)
48
49
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)
50
51
case _ => tree
51
52
52
53
object BetaReduce :
53
54
import ast .tpd ._
54
55
55
56
/** 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 ) =
57
58
val bindings = List .newBuilder[ValDef ]
58
59
val vparams = ddef.vparamss.iterator.flatten.toList
60
+ assert(args.hasSameLengthAs(vparams))
59
61
val argSyms =
60
62
for (arg, param) <- args.zip(vparams) yield
61
63
arg.tpe.dealias match
62
64
case ref @ TermRef (NoPrefix , _) if isPurePath(arg) =>
63
65
ref.symbol
64
66
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
71
71
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