diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeInfo.scala | 7 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 45 |
2 files changed, 19 insertions, 33 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala index cfdd258632..0c186c4f4f 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala @@ -113,9 +113,10 @@ abstract class TreeInfo { } /** The first constructor definitions in `stats' */ - def firstConstructor(stats: List[Tree]): Tree = stats.head match { - case constr @ DefDef(_, nme.CONSTRUCTOR, _, _, _, _) => constr - case _ => firstConstructor(stats.tail) + def firstConstructor(stats: List[Tree]): Tree = stats match { + case List() => EmptyTree + case (constr @ DefDef(_, nme.CONSTRUCTOR, _, _, _, _)) :: _ => constr + case _ :: stats1 => firstConstructor(stats1) } /* /** The super call that calls mixin `mix' in stats */ diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 1e663af07f..5cc654e6c8 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -528,25 +528,6 @@ trait Typers requires Analyzer { tree.tpe } -/* - def completeParentType(tpt: Tree, templ: Template): Tree = - if (tpt.hasSymbol) { - val tparams = tpt.symbol.typeParams - if (!tparams.isEmpty) { - val constr @ DefDef(_, _, _, vparamss, _, rhs) = treeInfo.firstConstructor(templ.body) - val Apply(_, superargs) = treeInfo.superCall(rhs, tpt.symbol.name) - val outercontext = context.outer - TypeTree( - newTyper(outercontext.makeNewScope(constr, outercontext.owner)) - .completeParentType( - tpt, - tparams, - context.owner.unsafeTypeParams, - vparamss map (.map(.duplicate.asInstanceOf[ValDef])), - superargs map (.duplicate))) setPos tpt.pos - } else tpt - } else tpt -*/ def parentTypes(templ: Template): List[Tree] = try { if (templ.parents.isEmpty) List() else { @@ -560,17 +541,21 @@ trait Typers requires Analyzer { if (supertpt.hasSymbol) { val tparams = supertpt.symbol.typeParams if (!tparams.isEmpty) { - val constr @ DefDef(_, _, _, vparamss, _, Apply(_, superargs)) = - treeInfo.firstConstructor(templ.body) - val outercontext = context.outer - supertpt = TypeTree( - newTyper(outercontext.makeNewScope(constr, outercontext.owner)) - .completeParentType( - supertpt, - tparams, - context.owner.unsafeTypeParams, - vparamss map (.map(.duplicate.asInstanceOf[ValDef])), - superargs map (.duplicate))) setOriginal supertpt /* setPos supertpt.pos */ + val constr = treeInfo.firstConstructor(templ.body) + constr match { + case EmptyTree => + error(supertpt.pos, "missing type arguments") + case DefDef(_, _, _, vparamss, _, Apply(_, superargs)) => + val outercontext = context.outer + supertpt = TypeTree( + newTyper(outercontext.makeNewScope(constr, outercontext.owner)) + .completeParentType( + supertpt, + tparams, + context.owner.unsafeTypeParams, + vparamss map (.map(.duplicate.asInstanceOf[ValDef])), + superargs map (.duplicate))) setOriginal supertpt /* setPos supertpt.pos */ + } } } //System.out.println("parents("+context.owner+") = "+supertpt :: mixins);//DEBUG |