Skip to content

Commit ce31908

Browse files
committed
Add Lambda method to tpd
A useful helper method to build a closure without having to define a symbol.
1 parent 160d4dd commit ce31908

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
104104
Closure(Nil, call, targetTpt))
105105
}
106106

107+
/** A closure whole anonymous function has the given method type */
108+
def Lambda(tpe: MethodType, rhsFn: List[Tree] => Tree)(implicit ctx: Context): Block = {
109+
val meth = ctx.newSymbol(ctx.owner, nme.ANON_FUN, Synthetic | Method, tpe)
110+
Closure(meth, tss => rhsFn(tss.head).changeOwner(ctx.owner, meth))
111+
}
112+
107113
def CaseDef(pat: Tree, guard: Tree, body: Tree)(implicit ctx: Context): CaseDef =
108114
ta.assignType(untpd.CaseDef(pat, guard, body), body)
109115

0 commit comments

Comments
 (0)