diff options
author | Martin Odersky <odersky@gmail.com> | 2015-04-30 12:02:08 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-05-02 19:07:38 +0200 |
commit | c395a2543ac0ad9ea53568b6b52d0effc5964645 (patch) | |
tree | ae2c18010111e5eccb082148306ef2c8a18e88aa | |
parent | 464ef81915cd428fc8918a2943ea4401ab0ef30a (diff) | |
download | dotty-c395a2543ac0ad9ea53568b6b52d0effc5964645.tar.gz dotty-c395a2543ac0ad9ea53568b6b52d0effc5964645.tar.bz2 dotty-c395a2543ac0ad9ea53568b6b52d0effc5964645.zip |
Generalize tpd.AnonClass
Now takes a list of parent types. We needed only one parent for SAM implementation
but it makes sense to generalize this.
Also, removed redundant code accidentally left in.
-rw-r--r-- | src/dotty/tools/dotc/ast/tpd.scala | 19 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/ExpandSAMs.scala | 4 |
2 files changed, 11 insertions, 12 deletions
diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index 4df3f7a63..dce06da95 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -247,22 +247,21 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { /** An anonymous class * - * new parent { forwarders } + * new parents { forwarders } * * where `forwarders` contains forwarders for all functions in `fns`. - * `fns` must be non-empty. The class has the same owner as the first function in `fns`. + * @param parents a non-empty list of class types + * @param fns a non-empty of functions for which forwarders should be defined in the class. + * The class has the same owner as the first function in `fns`. * Its position is the union of all functions in `fns`. */ - def AnonClass(parent: Type, fns: List[TermSymbol], methNames: List[TermName])(implicit ctx: Context): Block = { - def methName(fnName: TermName): TermName = if (fnName == nme.ANON_FUN) nme.apply else fnName + def AnonClass(parents: List[Type], fns: List[TermSymbol], methNames: List[TermName])(implicit ctx: Context): Block = { val owner = fns.head.owner - val parents = - if (parent.classSymbol.is(Trait)) defn.ObjectClass.typeRef :: parent :: Nil - else parent :: Nil - val cls = ctx.newNormalizedClassSymbol(owner, tpnme.ANON_FUN, Synthetic, parents, + val parents1 = + if (parents.head.classSymbol.is(Trait)) defn.ObjectClass.typeRef :: parents + else parents + val cls = ctx.newNormalizedClassSymbol(owner, tpnme.ANON_FUN, Synthetic, parents1, coord = fns.map(_.pos).reduceLeft(_ union _)) - println(i"creating anon class with parent $parent -> ${cls.info.parents}%, %") - println(cls.classInfo.classParents) val constr = ctx.newConstructor(cls, Synthetic, Nil, Nil).entered def forwarder(fn: TermSymbol, name: TermName) = { val fwdMeth = fn.copy(cls, name, Synthetic | Method).entered.asTerm diff --git a/src/dotty/tools/dotc/transform/ExpandSAMs.scala b/src/dotty/tools/dotc/transform/ExpandSAMs.scala index 1f822a12c..3b151dc31 100644 --- a/src/dotty/tools/dotc/transform/ExpandSAMs.scala +++ b/src/dotty/tools/dotc/transform/ExpandSAMs.scala @@ -33,7 +33,7 @@ class ExpandSAMs extends MiniPhaseTransform { thisTransformer => else tree case tpe => cpy.Block(tree)(stats, - AnonClass(tpe, fn.symbol.asTerm :: Nil, nme.apply :: Nil)) + AnonClass(tpe :: Nil, fn.symbol.asTerm :: Nil, nme.apply :: Nil)) } case _ => tree @@ -72,7 +72,7 @@ class ExpandSAMs extends MiniPhaseTransform { thisTransformer => tru } val isDefinedAtDef = transformFollowingDeep(DefDef(isDefinedAtFn, isDefinedAtRhs(_))) - val anonCls = AnonClass(tpt.tpe, List(applyFn, isDefinedAtFn), List(nme.apply, nme.isDefinedAt)) + val anonCls = AnonClass(tpt.tpe :: Nil, List(applyFn, isDefinedAtFn), List(nme.apply, nme.isDefinedAt)) cpy.Block(tree)(List(applyDef, isDefinedAtDef), anonCls) } } |