Skip to content

Commit 037eb2b

Browse files
committed
Allow closures to take type parameters.
This shouldn't require any changes to backend, as all type parameters will be erased in erasure Conflicts: src/dotty/tools/dotc/core/Symbols.scala
1 parent 94716b9 commit 037eb2b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
103103
* where the closure's type is the target type of the expression (FunctionN, unless
104104
* otherwise specified).
105105
*/
106-
def Closure(meth: TermSymbol, rhsFn: List[List[Tree]] => Tree, targetType: Type = NoType)(implicit ctx: Context): Block = {
106+
def Closure(meth: TermSymbol, rhsFn: List[List[Tree]] => Tree, targs: List[Tree] = Nil, targetType: Type = NoType)(implicit ctx: Context): Block = {
107107
val targetTpt = if (targetType.exists) TypeTree(targetType) else EmptyTree
108+
val call =
109+
if (targs.isEmpty) Ident(TermRef(NoPrefix, meth))
110+
else TypeApply(Ident(TermRef(NoPrefix, meth)), targs)
108111
Block(
109112
DefDef(meth, rhsFn) :: Nil,
110-
Closure(Nil, Ident(TermRef(NoPrefix, meth)), targetTpt))
113+
Closure(Nil, call, targetTpt))
111114
}
112115

113116
def CaseDef(pat: Tree, guard: Tree, body: Tree)(implicit ctx: Context): CaseDef =

src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ trait Symbols { this: Context =>
245245
for (name <- names) {
246246
val tparam = newNakedSymbol[TypeName](NoCoord)
247247
tparamBuf += tparam
248-
trefBuf += TypeRef(owner.thisType, name).withSym(tparam, Signature.NotAMethod)
248+
trefBuf += TypeRef.withSymAndName(owner.thisType, tparam, name)
249249
}
250250
val tparams = tparamBuf.toList
251251
val bounds = boundsFn(trefBuf.toList)
@@ -319,7 +319,7 @@ object Symbols {
319319
type ThisName <: Name
320320

321321
private[this] var _id: Int = nextId
322-
//assert(_id != 12325)
322+
//assert(_id != 5859)
323323

324324
/** The unique id of this symbol */
325325
def id = _id

0 commit comments

Comments
 (0)