diff options
Diffstat (limited to 'src/compiler')
29 files changed, 186 insertions, 184 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala index 6ee45b4676..f707fddfec 100644 --- a/src/compiler/scala/tools/nsc/Interpreter.scala +++ b/src/compiler/scala/tools/nsc/Interpreter.scala @@ -564,7 +564,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) for (ModuleDef(mods, name, _) <- trees if mods.isPublic) yield name val caseClasses = - for {val ClassDef(mods, name, _, _, _) <- trees + for {val ClassDef(mods, name, _, _) <- trees mods.isPublic mods.hasFlag(Flags.CASE)} yield name.toTermName @@ -573,7 +573,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) /** list of classes defined */ val classNames = - for (ClassDef(mods, name, _, _, _) <- trees if mods.isPublic) + for (ClassDef(mods, name, _, _) <- trees if mods.isPublic) yield name /** list of type aliases defined */ @@ -795,7 +795,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter) private class ClassReq(line: String, lineName: String) extends Request(line, lineName) { def newClassName = trees match { - case List(ClassDef(_, name, _, _, _)) => name + case List(ClassDef(_, name, _, _)) => name } def classdef = trees.head.asInstanceOf[ClassDef] diff --git a/src/compiler/scala/tools/nsc/ast/NodePrinters.scala b/src/compiler/scala/tools/nsc/ast/NodePrinters.scala index 83c87d0295..0cce3aec58 100644 --- a/src/compiler/scala/tools/nsc/ast/NodePrinters.scala +++ b/src/compiler/scala/tools/nsc/ast/NodePrinters.scala @@ -144,7 +144,7 @@ abstract class NodePrinters { } traverse(expr, level + 1, false) printcln(")") - case ClassDef(mods, name, tparams, tpt, impl) => + case ClassDef(mods, name, tparams, impl) => println("ClassDef(" + nodeinfo(tree)) println(" " + symflags(tree)) println(" \"" + name + "\",") @@ -190,7 +190,7 @@ abstract class NodePrinters { printcln(" \"" + selector + "\")") case Super(qual, mix) => printcln("Super(\"" + qual + "\", \"" + mix + "\")" + nodeinfo2(tree)) - case Template(parents, body) => + case Template(parents, self, body) => println("Template(," + nodeinfo(tree)) println(" " + parents.map(p => p.tpe.symbol) + ", // parents") if (body.isEmpty) diff --git a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala index 8ab01e697a..c13742860f 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala @@ -254,7 +254,7 @@ abstract class TreeBrowsers { case DocDef(comment, definition) => ("DocDef", EMPTY) - case ClassDef(mods, name, tparams, self, impl) => + case ClassDef(mods, name, tparams, impl) => ("ClassDef", name) case PackageDef(packaged, impl) => @@ -281,7 +281,7 @@ abstract class TreeBrowsers { case CaseDef(pat, guard, body) => ("CaseDef", EMPTY) - case Template(parents, body) => + case Template(parents, self, body) => ("Template", EMPTY) case LabelDef(name, params, rhs) => @@ -389,10 +389,10 @@ abstract class TreeBrowsers { case DocDef(comment, definition) => List(definition) - case ClassDef(mods, name, tparams, self, impl) => { + case ClassDef(mods, name, tparams, impl) => { var children: List[Tree] = List() children = tparams ::: children - self :: impl :: children + impl :: children } case PackageDef(name, stats) => @@ -428,8 +428,8 @@ abstract class TreeBrowsers { case CaseDef(pat, guard, body) => List(pat, guard, body) - case Template(parents, body) => - parents ::: body + case Template(parents, self, body) => + parents ::: List(self) ::: body case LabelDef(name, params, rhs) => params ::: List(rhs) diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala index dd567af5fe..40a7e26229 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala @@ -24,7 +24,7 @@ abstract class TreeInfo { def isOwnerDefinition(tree: Tree): boolean = tree match { case PackageDef(_, _) - | ClassDef(_, _, _, _, _) + | ClassDef(_, _, _, _) | ModuleDef(_, _, _) | DefDef(_, _, _, _, _, _) | Import(_, _) => true @@ -58,7 +58,7 @@ abstract class TreeInfo { */ def isPureDef(tree: Tree): boolean = tree match { case EmptyTree - | ClassDef(_, _, _, _, _) + | ClassDef(_, _, _, _) | AbsTypeDef(_, _, _, _, _) | AliasTypeDef(_, _, _, _) | Import(_, _) @@ -191,7 +191,7 @@ abstract class TreeInfo { /** can this type be a type pattern */ def mayBeTypePat(tree: Tree): boolean = tree match { - case CompoundTypeTree(Template(tps, List())) => tps exists mayBeTypePat + case CompoundTypeTree(Template(tps, _, List())) => tps exists mayBeTypePat case Annotated(_, tp) => mayBeTypePat(tp) case AppliedTypeTree(constr, args) => mayBeTypePat(constr) || args.exists(.isInstanceOf[Bind]) case SelectFromTypeTree(tp, _) => mayBeTypePat(tp) diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala index f331208752..a8c537cb8a 100644 --- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala +++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala @@ -122,20 +122,12 @@ abstract class TreePrinters { case EmptyTree => print("<empty>") - case ClassDef(mods, name, tparams, self, impl) => + case ClassDef(mods, name, tparams, impl) => printAnnotations(tree) printModifiers(tree, mods) print((if (mods hasFlag TRAIT) "trait " else "class ") + symName(tree, name)) printTypeParams(tparams) - print(" extends "); - printRow(impl.parents, " with ") - print(" {"); - if (self.name != nme.WILDCARD) { - print(" "); print(self.name); printOpt(": ", self.tpt); print(" => ") - } else if (!self.tpt.isEmpty) { - print(" _ : "); print(self.tpt); print(" => ") - } - printColumn(impl.body, "", ";", "}") + print(" extends "); print(impl) case PackageDef(packaged, stats) => printAnnotations(tree) @@ -197,9 +189,16 @@ abstract class TreePrinters { print((for (Assign(name, value) <- elements) yield "val " + name + " = " + value). mkString("{", ",", "}")) - case Template(parents, body) => + case Template(parents, self, body) => printRow(parents, " with ") - if (!body.isEmpty) printColumn(body, " {", ";", "}") + if (!body.isEmpty) { + if (self.name != nme.WILDCARD) { + print(" { "); print(self.name); printOpt(": ", self.tpt); print(" => ") + } else if (!self.tpt.isEmpty) { + print(" _ : "); print(self.tpt); print(" => ") + } + printColumn(body, "", ";", "}") + } case Block(stats, expr) => printColumn(stats ::: List(expr), "{", ";", "}") @@ -341,7 +340,7 @@ abstract class TreePrinters { printRaw( if (tree.isDef && tree.symbol != NoSymbol) { tree match { - case ClassDef(_, _, _, _, impl) => ClassDef(tree.symbol, impl) + case ClassDef(_, _, _, impl) => ClassDef(tree.symbol, impl) case ModuleDef(_, _, impl) => ModuleDef(tree.symbol, impl) // case ValDef(_, _, _, rhs) => ValDef(tree.symbol, rhs) case DefDef(_, _, _, vparamss, _, rhs) => DefDef(tree.symbol, vparamss, rhs) diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index fc47701fe8..c28b0de4e9 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -200,7 +200,7 @@ trait Trees { def mods: Modifiers def keyword: String = this match { case AliasTypeDef(_, _, _, _) => "type" - case ClassDef(_, _, _, _, _) => "class" + case ClassDef(_, _, _, _) => "class" case DefDef(_, _, _, _, _, _) => "def" case ModuleDef(_, _, _) => "object" case PackageDef(_, _) => "package" @@ -224,7 +224,7 @@ trait Trees { } /** Class definition */ - case class ClassDef(mods: Modifiers, name: Name, tparams: List[AbsTypeDef], self: ValDef, impl: Template) + case class ClassDef(mods: Modifiers, name: Name, tparams: List[AbsTypeDef], impl: Template) extends ImplDef /** @@ -237,7 +237,6 @@ trait Trees { ClassDef(Modifiers(sym.flags), sym.name, sym.typeParams map AbsTypeDef, - if (sym.thisSym == sym || phase.erasedTypes) emptyValDef else ValDef(sym.thisSym), impl) setSymbol sym } @@ -253,7 +252,10 @@ trait Trees { * @return ... */ def ClassDef(sym: Symbol, constrMods: Modifiers, vparamss: List[List[ValDef]], argss: List[List[Tree]], body: List[Tree]): ClassDef = - ClassDef(sym, Template(sym.info.parents map TypeTree, constrMods, vparamss, argss, body)) + ClassDef(sym, + Template(sym.info.parents map TypeTree, + if (sym.thisSym == sym || phase.erasedTypes) emptyValDef else ValDef(sym.thisSym), + constrMods, vparamss, argss, body)) /** Singleton object definition * @@ -301,7 +303,10 @@ trait Trees { def ValDef(sym: Symbol): ValDef = ValDef(sym, EmptyTree) - object emptyValDef extends ValDef(Modifiers(PRIVATE), nme.WILDCARD, TypeTree(NoType), EmptyTree) + object emptyValDef + extends ValDef(Modifiers(PRIVATE), nme.WILDCARD, TypeTree(NoType), EmptyTree) { + override def isEmpty = true + } /** Method definition * @@ -434,7 +439,7 @@ trait Trees { * @param parents * @param body */ - case class Template(parents: List[Tree], body: List[Tree]) + case class Template(parents: List[Tree], self: ValDef, body: List[Tree]) extends SymTree { // System.err.println("TEMPLATE: " + parents) } @@ -446,7 +451,7 @@ trait Trees { * @param body ... * @return ... */ - def Template(parents: List[Tree], constrMods: Modifiers, vparamss: List[List[ValDef]], argss: List[List[Tree]], body: List[Tree]): Template = { + def Template(parents: List[Tree], self: ValDef, constrMods: Modifiers, vparamss: List[List[ValDef]], argss: List[List[Tree]], body: List[Tree]): Template = { /** Add constructor to template */ var vparamss1 = vparamss map (.map (vd => { @@ -478,7 +483,7 @@ trait Trees { List( DefDef(constrMods, nme.CONSTRUCTOR, List(), vparamss1, TypeTree(), Block(lvdefs ::: List(superCall), Literal(())))) } - Template(parents, gvdefs ::: List.flatten(vparamss) ::: constrs ::: rest) + Template(parents, self, gvdefs ::: List.flatten(vparamss) ::: constrs ::: rest) } /** Block of expressions (semicolon separated expressions) */ @@ -721,8 +726,8 @@ trait Trees { case EmptyTree => case PackageDef(name, stats) => // package name { stats } - case ClassDef(mods, name, tparams, self, impl) => - // mods class name[tparams] requires self impl + case ClassDef(mods, name, tparams, impl) => + // mods class name[tparams] impl case ModuleDef(mods, name, impl) => (eliminated by refcheck) // mods object name impl where impl = extends parents { defs } case ValDef(mods, name, tpt, rhs) => @@ -741,8 +746,8 @@ trait Trees { // @constr(elements) where constr = tp(args), elements = { val x1 = c1, ..., val xn = cn } case DocDef(comment, definition) => (eliminated by typecheck) // /** comment */ definition - case Template(parents, body) => - // extends parents { body } + case Template(parents, self, body) => + // extends parents { self => body } case Block(stats, expr) => // { stats; expr } case CaseDef(pat, guard, body) => (eliminated by transmatch/explicitouter) @@ -810,7 +815,7 @@ trait Trees { */ abstract class TreeCopier { - def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], self: ValDef, impl: Template): ClassDef + def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], impl: Template): ClassDef def PackageDef(tree: Tree, name: Name, stats: List[Tree]): PackageDef def ModuleDef(tree: Tree, mods: Modifiers, name: Name, impl: Template): ModuleDef def ValDef(tree: Tree, mods: Modifiers, name: Name, tpt: Tree, rhs: Tree): ValDef @@ -821,7 +826,7 @@ trait Trees { def Import(tree: Tree, expr: Tree, selectors: List[(Name, Name)]): Import def Annotation(tree: Tree, constr: Tree, elements: List[Tree]): Annotation def DocDef(tree: Tree, comment: String, definition: Tree): DocDef - def Template(tree: Tree, parents: List[Tree], body: List[Tree]): Template + def Template(tree: Tree, parents: List[Tree], self: ValDef, body: List[Tree]): Template def Block(tree: Tree, stats: List[Tree], expr: Tree): Block def CaseDef(tree: Tree, pat: Tree, guard: Tree, body: Tree): CaseDef def Sequence(tree: Tree, trees: List[Tree]): Sequence @@ -857,8 +862,8 @@ trait Trees { } class StrictTreeCopier extends TreeCopier { - def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], self: ValDef, impl: Template) = - new ClassDef(mods, name, tparams, self, impl).copyAttrs(tree); + def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], impl: Template) = + new ClassDef(mods, name, tparams, impl).copyAttrs(tree); def PackageDef(tree: Tree, name: Name, stats: List[Tree]) = new PackageDef(name, stats).copyAttrs(tree) def ModuleDef(tree: Tree, mods: Modifiers, name: Name, impl: Template) = @@ -879,8 +884,8 @@ trait Trees { new Annotation(constr, elements).copyAttrs(tree) def DocDef(tree: Tree, comment: String, definition: Tree) = new DocDef(comment, definition).copyAttrs(tree) - def Template(tree: Tree, parents: List[Tree], body: List[Tree]) = - new Template(parents, body).copyAttrs(tree) + def Template(tree: Tree, parents: List[Tree], self: ValDef, body: List[Tree]) = + new Template(parents, self, body).copyAttrs(tree) def Block(tree: Tree, stats: List[Tree], expr: Tree) = new Block(stats, expr).copyAttrs(tree) def CaseDef(tree: Tree, pat: Tree, guard: Tree, body: Tree) = @@ -949,10 +954,10 @@ trait Trees { class LazyTreeCopier(copy: TreeCopier) extends TreeCopier { def this() = this(new StrictTreeCopier) - def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], self: ValDef, impl: Template) = tree match { - case t @ ClassDef(mods0, name0, tparams0, self0, impl0) - if (mods0 == mods && (name0 == name) && (tparams0 == tparams) && (self0 == self) && (impl0 == impl)) => t - case _ => copy.ClassDef(tree, mods, name, tparams, self, impl) + def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], impl: Template) = tree match { + case t @ ClassDef(mods0, name0, tparams0, impl0) + if (mods0 == mods && (name0 == name) && (tparams0 == tparams) && (impl0 == impl)) => t + case _ => copy.ClassDef(tree, mods, name, tparams, impl) } def PackageDef(tree: Tree, name: Name, stats: List[Tree]) = tree match { case t @ PackageDef(name0, stats0) @@ -1005,10 +1010,10 @@ trait Trees { if (comment0 == comment) && (definition0 == definition) => t case _ => copy.DocDef(tree, comment, definition) } - def Template(tree: Tree, parents: List[Tree], body: List[Tree]) = tree match { - case t @ Template(parents0, body0) - if (parents0 == parents) && (body0 == body) => t - case _ => copy.Template(tree, parents, body) + def Template(tree: Tree, parents: List[Tree], self: ValDef, body: List[Tree]) = tree match { + case t @ Template(parents0, self0, body0) + if (parents0 == parents) && (self0 == self) && (body0 == body) => t + case _ => copy.Template(tree, parents, self, body) } def Block(tree: Tree, stats: List[Tree], expr: Tree) = tree match { case t @ Block(stats0, expr0) @@ -1184,12 +1189,9 @@ trait Trees { atOwner(tree.symbol.moduleClass) { copy.PackageDef(tree, name, transformStats(stats, currentOwner)) } - case ClassDef(mods, name, tparams, self, impl) => + case ClassDef(mods, name, tparams, impl) => atOwner(tree.symbol) { - copy.ClassDef(tree, mods, name, - transformAbsTypeDefs(tparams), - if (self ne emptyValDef) transformValDef(self) else self, - transformTemplate(impl)) + copy.ClassDef(tree, mods, name, transformAbsTypeDefs(tparams), transformTemplate(impl)) } case ModuleDef(mods, name, impl) => atOwner(tree.symbol.moduleClass) { @@ -1220,8 +1222,8 @@ trait Trees { copy.Annotation(tree, transform(constr), transformTrees(elements)) case DocDef(comment, definition) => copy.DocDef(tree, comment, transform(definition)) - case Template(parents, body) => - copy.Template(tree, transformTrees(parents), transformStats(body, tree.symbol)) + case Template(parents, self, body) => + copy.Template(tree, transformTrees(parents), transformValDef(self), transformStats(body, tree.symbol)) case Block(stats, expr) => copy.Block(tree, transformStats(stats, currentOwner), transform(expr)) case CaseDef(pat, guard, body) => @@ -1297,7 +1299,7 @@ trait Trees { def transformAbsTypeDefs(trees: List[AbsTypeDef]): List[AbsTypeDef] = List.mapConserve(trees)(tree => transform(tree).asInstanceOf[AbsTypeDef]) def transformValDef(tree: ValDef): ValDef = - transform(tree).asInstanceOf[ValDef] + if (tree.isEmpty) tree else transform(tree).asInstanceOf[ValDef] def transformValDefs(trees: List[ValDef]): List[ValDef] = List.mapConserve(trees)(transformValDef) def transformValDefss(treess: List[List[ValDef]]): List[List[ValDef]] = @@ -1330,11 +1332,9 @@ trait Trees { atOwner(tree.symbol.moduleClass) { traverseTrees(stats) } - case ClassDef(mods, name, tparams, self, impl) => + case ClassDef(mods, name, tparams, impl) => atOwner(tree.symbol) { - traverseTrees(tparams); - if (self ne emptyValDef) traverse(self); - traverse(impl) + traverseTrees(tparams); traverse(impl) } case ModuleDef(mods, name, impl) => atOwner(tree.symbol.moduleClass) { @@ -1366,8 +1366,10 @@ trait Trees { traverse(annot); traverse(arg) case DocDef(comment, definition) => traverse(definition) - case Template(parents, body) => - traverseTrees(parents); traverseStats(body, tree.symbol) + case Template(parents, self, body) => + traverseTrees(parents) + if (!self.isEmpty) traverse(self) + traverseStats(body, tree.symbol) case Block(stats, expr) => traverseTrees(stats); traverse(expr) case CaseDef(pat, guard, body) => @@ -1536,7 +1538,7 @@ trait Trees { override def traverse(tree: Tree): unit = tree match { case EmptyTree | TypeTree() => ; - case Template(parents, body) => + case Template(parents, self, body) => tree.symbol = NoSymbol tree.tpe = null for (stat <- body) diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 57e098f0b4..63d9115063 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -702,7 +702,8 @@ trait Parsers { } newLineOptWhenFollowedBy(LBRACE) atPos(pos) { - if (inToken == LBRACE && !isPattern) CompoundTypeTree(Template(ts.toList, refinement())) + if (inToken == LBRACE && !isPattern) + CompoundTypeTree(Template(ts.toList, emptyValDef, refinement())) else makeIntersectionTypeTree(ts.toList) } } @@ -2058,14 +2059,18 @@ trait Parsers { if (mods.hasFlag(Flags.TRAIT)) (Modifiers(Flags.TRAIT), List()) else (accessModifierOpt(), paramClauses(name, implicitClassViews, mods.hasFlag(Flags.CASE))) val thistpe = requiresTypeOpt() - val (self0, template) = - templateOpt(mods, name, constrMods withAnnotations constrAnnots, vparamss) + var template = templateOpt(mods, name, constrMods withAnnotations constrAnnots, vparamss) + if (!thistpe.isEmpty) { + if (template.self.isEmpty) { + template = copy.Template( + template, template.parents, makeSelfDef(nme.WILDCARD, thistpe), template.body) + } else syntaxError("`requires' cannot be combined with explicit self type", false) + } val mods1 = if (mods.hasFlag(Flags.TRAIT) && (template.body forall treeInfo.isInterfaceMember)) mods | Flags.INTERFACE else mods - val self = if (thistpe.isEmpty) self0 else makeSelfDef(nme.WILDCARD, thistpe) - val result = ClassDef(mods1, name, tparams, self, template) + val result = ClassDef(mods1, name, tparams, template) implicitClassViews = savedViews result } @@ -2075,14 +2080,7 @@ trait Parsers { def objectDef(mods: Modifiers): ModuleDef = atPos(inSkipToken) { val name = ident() - val (self, template0) = templateOpt(mods, name, NoMods, List()) - val template = self match { - case ValDef(mods, name, tpt, EmptyTree) if (name != nme.WILDCARD) => - val vd = ValDef(mods, name, tpt, This(nme.EMPTY.toTypeName)) setPos self.pos - Template(template0.parents, vd :: template0.body) - case _ => - template0 - } + val template = templateOpt(mods, name, NoMods, List()) ModuleDef(mods, name, template) } @@ -2112,7 +2110,7 @@ trait Parsers { newLineOptWhenFollowedBy(LBRACE) if (inToken == LBRACE) { val (self, body) = templateBody() - if (inToken == WITH && (self eq emptyValDef)) { + if (inToken == WITH && self.isEmpty) { val vdefs: List[ValDef] = body flatMap { case vdef @ ValDef(mods, name, tpt, rhs) if !(mods hasFlag Flags.DEFERRED) => List(copy.ValDef(vdef, mods | Flags.PRESUPER, name, tpt, rhs)) @@ -2137,7 +2135,7 @@ trait Parsers { /** ClassTemplateOpt ::= extends ClassTemplate | [[extends] TemplateBody] * TraitTemplateOpt ::= extends TraitTemplate | [[extends] TemplateBody] */ - def templateOpt(mods: Modifiers, name: Name, constrMods: Modifiers, vparamss: List[List[ValDef]]): (ValDef, Template) = { + def templateOpt(mods: Modifiers, name: Name, constrMods: Modifiers, vparamss: List[List[ValDef]]): Template = { val pos = inCurrentPos; val (parents0, argss, self, body) = if (inToken == EXTENDS) { @@ -2151,7 +2149,7 @@ trait Parsers { var parents = parents0 if (name != nme.ScalaObject.toTypeName) parents = parents ::: List(scalaScalaObjectConstr) if (mods.hasFlag(Flags.CASE)) parents = parents ::: List(productConstr) - (self, atPos(pos) { Template(parents, constrMods, vparamss, argss, body) }) + atPos(pos) { Template(parents, self, constrMods, vparamss, argss, body) } } ////////// TEMPLATES //////////////////////////////////////////////////////////// diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index 63e368480d..e53dd1c66b 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -146,8 +146,8 @@ abstract class TreeBuilder { val x = nme.ANON_CLASS_NAME.toTypeName Block( List(ClassDef( - Modifiers(FINAL | SYNTHETIC), x, List(), self, - Template(parents, NoMods, List(List()), argss, stats))), + Modifiers(FINAL | SYNTHETIC), x, List(), + Template(parents, self, NoMods, List(List()), argss, stats))), New(Ident(x), List(List()))) } @@ -160,7 +160,7 @@ abstract class TreeBuilder { /** A type tree corresponding to (possibly unary) intersection type */ def makeIntersectionTypeTree(tps: List[Tree]): Tree = if (tps.tail.isEmpty) tps.head - else CompoundTypeTree(Template(tps, List())) + else CompoundTypeTree(Template(tps, emptyValDef, List())) /** Create tree representing a while loop */ def makeWhile(lname: Name, cond: Tree, body: Tree): Tree = { diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index 3cf3034dcf..e10691420d 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -82,7 +82,7 @@ abstract class GenICode extends SubComponent { case PackageDef(name, stats) => gen(stats, ctx setPackage name) - case ClassDef(mods, name, _, _, impl) => + case ClassDef(mods, name, _, impl) => log("Generating class: " + tree.symbol.fullNameString) ctx setClass (new IClass(tree.symbol) setCompilationUnit unit) addClassFields(ctx, tree.symbol); @@ -132,7 +132,7 @@ abstract class GenICode extends SubComponent { ctx1.method.setCode(null) ctx1 - case Template(parents, body) => + case Template(_, _, body) => gen(body, ctx) case _ => diff --git a/src/compiler/scala/tools/nsc/symtab/Scopes.scala b/src/compiler/scala/tools/nsc/symtab/Scopes.scala index dfc5f6dd54..d63d51ac09 100644 --- a/src/compiler/scala/tools/nsc/symtab/Scopes.scala +++ b/src/compiler/scala/tools/nsc/symtab/Scopes.scala @@ -222,11 +222,13 @@ trait Scopes { var e: ScopeEntry = null if (hashtable ne null) { e = hashtable(name.start & HASHMASK) - while ((e ne null) && e.sym.name != name) e = e.tail; + while ((e ne null) && e.sym.name != name) { + e = e.tail + } } else { e = elems while ((e ne null) && e.sym.name != name) { - e = e.next; + e = e.next } } e diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala index 8371a8a857..cc922e54ab 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala @@ -41,7 +41,7 @@ abstract class Pickler extends SubComponent { tree match { case PackageDef(_, stats) => stats foreach pickle - case ClassDef(_, _, _, _, _) | ModuleDef(_, _, _) => + case ClassDef(_, _, _, _) | ModuleDef(_, _, _) => val sym = tree.symbol val pickle = new Pickle(sym.name.toTermName, sym.owner) add(sym, pickle) diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala index 815b36b361..269e2fb247 100644 --- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala +++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala @@ -229,7 +229,7 @@ abstract class AddInterfaces extends InfoTransform { else tree private def ifaceTemplate(templ: Template): Template = - copy.Template(templ, templ.parents, templ.body map ifaceMemberDef) + copy.Template(templ, templ.parents, emptyValDef, templ.body map ifaceMemberDef) private def implMethodDef(tree: Tree, ifaceMethod: Symbol): Tree = implMethodMap.get(ifaceMethod) match { @@ -255,7 +255,8 @@ abstract class AddInterfaces extends InfoTransform { private def implTemplate(clazz: Symbol, templ: Template): Template = atPos(templ.pos) { val templ1 = atPos(templ.pos) { - Template(templ.parents, addMixinConstructorDef(clazz, templ.body map implMemberDef)) + Template(templ.parents, emptyValDef, + addMixinConstructorDef(clazz, templ.body map implMemberDef)) .setSymbol(clazz.newLocalDummy(templ.pos)) } new ChangeOwnerTraverser(templ.symbol.owner, clazz)( @@ -266,7 +267,7 @@ abstract class AddInterfaces extends InfoTransform { val buf = new ListBuffer[Tree] for (val tree <- trees) tree match { - case ClassDef(_, _, _, _, impl) => + case ClassDef(_, _, _, impl) => if (tree.symbol.needsImplClass) buf += { val clazz = implClass(tree.symbol).initialize @@ -306,16 +307,16 @@ abstract class AddInterfaces extends InfoTransform { override def transform(tree: Tree): Tree = { val sym = tree.symbol val tree1 = tree match { - case ClassDef(mods, name, tparams, self, impl) if (sym.needsImplClass) => + case ClassDef(mods, name, tparams, impl) if (sym.needsImplClass) => implClass(sym).initialize // to force lateDEFERRED flags - copy.ClassDef(tree, mods | INTERFACE, name, tparams, self, ifaceTemplate(impl)) + copy.ClassDef(tree, mods | INTERFACE, name, tparams, ifaceTemplate(impl)) case DefDef(mods, name, tparams, vparamss, tpt, rhs) if (sym.isClassConstructor && sym.isPrimaryConstructor && sym.owner != ArrayClass) => copy.DefDef(tree, mods, name, tparams, vparamss, tpt, addMixinConstructorCalls(rhs, sym.owner)) // (3) - case Template(parents, body) => + case Template(parents, self, body) => val parents1 = sym.owner.info.parents map (t => TypeTree(t) setPos tree.pos) - copy.Template(tree, parents1, body) + copy.Template(tree, parents1, emptyValDef, body) case This(_) => if (sym.needsImplClass) { val impl = implClass(sym) diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index ad0912cafc..27882f588f 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -90,12 +90,12 @@ abstract class CleanUp extends Transform { } override def transform(tree: Tree): Tree = tree match { - case Template(parents, body) => + case Template(parents, self, body) => classConstantMeth.clear newDefs.clear localTyper = typer.atOwner(tree, currentOwner) val body1 = transformTrees(body) - copy.Template(tree, parents, newDefs.toList ::: body1) + copy.Template(tree, parents, self, newDefs.toList ::: body1) case Literal(c) if (c.tag == ClassTag) => val tpe = c.typeValue atPos(tree.pos) { diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala index 72df84c9b3..98efdb426a 100644 --- a/src/compiler/scala/tools/nsc/transform/Constructors.scala +++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala @@ -161,7 +161,7 @@ abstract class Constructors extends Transform { } defBuf += copy.ValDef(stat, mods, name, tpt, EmptyTree) } - case ClassDef(_, _, _, _, _) => + case ClassDef(_, _, _, _) => defBuf += (new ConstructorTransformer).transform(stat) case _ => constrStatBuf += intoConstructor(impl.symbol, stat) @@ -201,13 +201,14 @@ abstract class Constructors extends Transform { for (sym <- clazz.info.decls.toList) if (!isAccessed(sym)) clazz.info.decls unlink sym - copy.Template(impl, impl.parents, defBuf.toList filter (stat => isAccessed(stat.symbol))) + copy.Template(impl, impl.parents, impl.self, + defBuf.toList filter (stat => isAccessed(stat.symbol))) } override def transform(tree: Tree): Tree = { tree match { - case ClassDef(mods, name, tparams, self, impl) if !tree.symbol.hasFlag(INTERFACE) => - copy.ClassDef(tree, mods, name, tparams, self, transformClassTemplate(impl)) + case ClassDef(mods, name, tparams, impl) if !tree.symbol.hasFlag(INTERFACE) => + copy.ClassDef(tree, mods, name, tparams, transformClassTemplate(impl)) case _ => super.transform(tree) } diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index ddee05f16e..69d5b4ae9b 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -742,10 +742,10 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer { override def transform(tree: Tree): Tree = { if (tree.symbol == ArrayClass) return tree val tree1 = tree match { - case ClassDef(mods, name, tparams, self, impl) => + case ClassDef(mods, name, tparams, impl) => if (settings.debug.value) log("defs of " + tree.symbol + " = " + tree.symbol.info.decls) - copy.ClassDef(tree, mods, name, List(), emptyValDef, impl) + copy.ClassDef(tree, mods, name, List(), impl) case DefDef(mods, name, tparams, vparamss, tpt, rhs) => copy.DefDef(tree, mods, name, List(), vparamss, tpt, rhs) case AbsTypeDef(_, _, _, _, _) => @@ -830,11 +830,11 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer { } tree - case Template(parents, body) => + case Template(parents, self, body) => assert(!currentOwner.isImplClass) //Console.println("checking no dble defs " + tree)//DEBUG checkNoDoubleDefs(tree.symbol.owner) - copy.Template(tree, parents, addBridges(body, currentOwner)) + copy.Template(tree, parents, emptyValDef, addBridges(body, currentOwner)) case _ => tree } diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala index 50b9095ea8..e1ba10a064 100644 --- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala +++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala @@ -190,7 +190,7 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter val savedOuterParam = outerParam try { tree match { - case Template(_, _) => + case Template(_, _, _) => outerParam = NoSymbol case DefDef(_, _, _, vparamss, _, _) => if (tree.symbol.isClassConstructor && isInner(tree.symbol.owner)) { @@ -320,7 +320,7 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter if (sym hasFlag PROTECTED) sym setFlag notPROTECTED } tree match { - case Template(parents, decls) => + case Template(parents, self, decls) => val newDefs = new ListBuffer[Tree] atOwner(tree, currentOwner) { if (!(currentClass hasFlag INTERFACE) || (currentClass hasFlag lateINTERFACE)) { @@ -336,7 +336,8 @@ abstract class ExplicitOuter extends InfoTransform with TransMatcher with Patter } } super.transform( - copy.Template(tree, parents, if (newDefs.isEmpty) decls else decls ::: newDefs.toList) + copy.Template(tree, parents, self, + if (newDefs.isEmpty) decls else decls ::: newDefs.toList) ) case DefDef(mods, name, tparams, vparamss, tpt, rhs) => if (sym.isClassConstructor) { diff --git a/src/compiler/scala/tools/nsc/transform/Flatten.scala b/src/compiler/scala/tools/nsc/transform/Flatten.scala index f64fceb6c3..df833b036d 100644 --- a/src/compiler/scala/tools/nsc/transform/Flatten.scala +++ b/src/compiler/scala/tools/nsc/transform/Flatten.scala @@ -85,7 +85,7 @@ abstract class Flatten extends InfoTransform { private def postTransform(tree: Tree): Tree = { val sym = tree.symbol val tree1 = tree match { - case ClassDef(_, _, _, _, _) if sym.isNestedClass => + case ClassDef(_, _, _, _) if sym.isNestedClass => liftedDefs(sym.toplevelClass.owner) += tree EmptyTree case Select(qual, name) if (sym.isStaticModule && !sym.owner.isPackageClass) => diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala index 3ffffcf3bf..981f137dcc 100644 --- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala +++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala @@ -192,7 +192,7 @@ abstract class LambdaLift extends InfoTransform { try { //debug val sym = tree.symbol; tree match { - case ClassDef(_, _, _, _, _) => + case ClassDef(_, _, _, _) => liftedDefs(tree.symbol) = new ListBuffer if (sym.isLocal) renamable addEntry sym case DefDef(_, _, _, _, _, _) => @@ -321,9 +321,9 @@ abstract class LambdaLift extends InfoTransform { sym.updateInfo( lifted(MethodType(sym.info.paramTypes ::: (ps map (.tpe)), sym.info.resultType))); copy.DefDef(tree, mods, name, tparams, List(vparams ::: freeParams), tpt, rhs) - case ClassDef(mods, name, tparams, self, impl @ Template(parents, body)) => - copy.ClassDef(tree, mods, name, tparams, self, - copy.Template(impl, parents, body ::: freeParams)) + case ClassDef(mods, name, tparams, impl @ Template(parents, self, body)) => + copy.ClassDef(tree, mods, name, tparams, + copy.Template(impl, parents, self, body ::: freeParams)) } case None => tree @@ -343,7 +343,7 @@ abstract class LambdaLift extends InfoTransform { private def postTransform(tree: Tree): Tree = { val sym = tree.symbol tree match { - case ClassDef(_, _, _, _, _) => + case ClassDef(_, _, _, _) => val tree1 = addFreeParams(tree, sym) if (sym.isLocal) liftDef(tree1) else tree1 case DefDef(_, _, _, _, _, _) => @@ -399,10 +399,10 @@ abstract class LambdaLift extends InfoTransform { /** Transform statements and add lifted definitions to them. */ override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = { def addLifted(stat: Tree): Tree = stat match { - case ClassDef(mods, name, tparams, self, impl @ Template(parents, body)) => + case ClassDef(mods, name, tparams, impl @ Template(parents, self, body)) => val lifted = liftedDefs(stat.symbol).toList map addLifted val result = copy.ClassDef( - stat, mods, name, tparams, self, copy.Template(impl, parents, body ::: lifted)) + stat, mods, name, tparams, copy.Template(impl, parents, self, body ::: lifted)) liftedDefs -= stat.symbol result case _ => diff --git a/src/compiler/scala/tools/nsc/transform/LiftCode.scala b/src/compiler/scala/tools/nsc/transform/LiftCode.scala index a77411093f..77d0992617 100644 --- a/src/compiler/scala/tools/nsc/transform/LiftCode.scala +++ b/src/compiler/scala/tools/nsc/transform/LiftCode.scala @@ -133,16 +133,17 @@ abstract class LiftCode extends Transform { val rhs_ = reify(rhs) reflect.ValDef(sym, rhs_) - case cd @ ClassDef(mods, name, tparams, self, impl) => + case cd @ ClassDef(mods, name, tparams, impl) => if(!tparams.isEmpty) throw new TypeError("cannot handle polymorphic ClassDef ("+name+"): " + tparams) val rsym = reify(cd.symbol) val rimp = reify(impl) - val rtpe = reify(self.tpt.tpe) //todo: update + val rtpe = reify(impl.self.tpt.tpe) //todo: update reflect.ClassDef(rsym, rtpe, rimp.asInstanceOf[reflect.Template]) - case tmpl @ Template(parents, body) => + case tmpl @ Template(parents, self, body) => val rparents = for (p <- parents) yield { reify(p.tpe) } + //todo: add self to reified templates reflect.Template(rparents, body.map(reify)) case dd @ DefDef(mods, name, tparams, vparamss, tpt, rhs) => @@ -309,13 +310,13 @@ abstract class LiftCode extends Transform { // case EmptyTree => // case LiftPoint(tree) => // case PackageDef(name, stats) => -// case ClassDef(mods, name, tparams, self, impl) => +// case ClassDef(mods, name, tparams, impl) => // case ValDef(mods, name, tpt, rhs) => // case DefDef(mods, name, tparams, vparamss, tpt, rhs) => // case AbsTypeDef(mods, name, tparams, lo, hi) => // case AliasTypeDef(mods, name, tparams, rhs) => // case LabelDef(name, params, rhs) => -// case Template(parents, body) => +// case Template(parents, self, body) => // case Block(stats, expr) => // case ArrayValue(elemtpt, trees) => // case Assign(lhs, rhs) => diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala index d9bd6cc225..9fb36a43ad 100644 --- a/src/compiler/scala/tools/nsc/transform/Mixin.scala +++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala @@ -339,7 +339,7 @@ abstract class Mixin extends InfoTransform { private def preTransform(tree: Tree): Tree = { val sym = tree.symbol tree match { - case Template(parents, body) => + case Template(parents, self, body) => localTyper = erasure.newTyper(rootContext.make(tree, currentOwner)) atPhase(phase.next)(currentOwner.owner.info)//todo: needed? if (!currentOwner.isTrait) addMixedinMembers(currentOwner) @@ -554,14 +554,14 @@ abstract class Mixin extends InfoTransform { tree.tpe = toInterface(tree.tpe); tree match { - case Template(parents, body) => + case Template(parents, self, body) => // change parents of templates to conform to parents in the symbol info val parents1 = currentOwner.info.parents map (t => TypeTree(t) setPos tree.pos) // add all new definitions to current class or interface val body1 = addNewDefs(currentOwner, body) - copy.Template(tree, parents1, body1) + copy.Template(tree, parents1, self, body1) case Apply(TypeApply(sel @ Select(qual, name), List(targ)), List()) if (tree.symbol == Object_asInstanceOf && (qual.tpe <:< targ.tpe)) => diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala index 33fb254f48..7862398495 100644 --- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala +++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala @@ -188,7 +188,7 @@ abstract class TailCalls extends Transform case PackageDef(name, stats) => super.transform(tree) - case ClassDef(_, name, _, _, _) => + case ClassDef(_, name, _, _) => log("Entering class " + name) val res = super.transform(tree) log("Leaving class " + name) @@ -199,7 +199,7 @@ abstract class TailCalls extends Transform case AliasTypeDef(mods, name, tparams, rhs) => tree // (eliminated by erasure) case LabelDef(name, params, rhs) => super.transform(tree) - case Template(parents, body) => + case Template(parents, self, body) => super.transform(tree) case Block(stats, expr) => diff --git a/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala b/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala index da158a0553..b775d95ecf 100644 --- a/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala +++ b/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala @@ -39,7 +39,7 @@ trait TypingTransformers { override def transform(tree: Tree): Tree = { curTree = tree tree match { - case Template(_, _) => + case Template(_, _, _) => // enter template into context chain atOwner(currentOwner) { super.transform(tree) } case _ => diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index c0e29a55e1..3a434f3b6c 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -444,7 +444,7 @@ abstract class UnCurry extends InfoTransform with TypingTransformers { case fun @ Function(_, _) => mainTransform(transformFunction(fun)) - case Template(_, _) => + case Template(_, _, _) => withInConstructorFlag(0) { super.transform(tree) } case _ => diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index a4990fc865..4e4e95e25b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -26,7 +26,7 @@ trait Contexts requires Analyzer { private val startContext = { NoContext.make( - global.Template(List(), List()) setSymbol global.NoSymbol setType global.NoType, + global.Template(List(), emptyValDef, List()) setSymbol global.NoSymbol setType global.NoType, global.definitions.RootClass, global.definitions.RootClass.info.decls) } @@ -157,7 +157,7 @@ trait Contexts requires Analyzer { c.owner = owner c.scope = scope tree match { - case Template(_, _) | PackageDef(_, _) => + case Template(_, _, _) | PackageDef(_, _) => c.enclClass = c c.prefix = c.owner.thisType c.inConstructorSuffix = false diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 00d10e7479..236d46a272 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -73,7 +73,7 @@ trait Namers requires Analyzer { } private def isTemplateContext(context: Context): boolean = context.tree match { - case Template(_, _) => true + case Template(_, _, _) => true case Import(_, _) => isTemplateContext(context.outer) case _ => false } @@ -271,7 +271,7 @@ trait Namers requires Analyzer { val namer = new Namer( context.make(tree, tree.symbol.moduleClass, tree.symbol.info.decls)) namer.enterSyms(stats) - case ClassDef(mods, name, tparams, _, impl) => + case ClassDef(mods, name, tparams, impl) => if ((mods.flags & CASE) != 0) { // enter case factory method. tree.symbol = enterCaseFactorySymbol( tree.pos, mods.flags & AccessFlags | METHOD | CASE, name.toTermName) @@ -423,8 +423,7 @@ trait Namers requires Analyzer { vparamss.map(.map(enterValueParam)) } - private def templateSig(templ0: Template): Type = { - var templ = templ0 + private def templateSig(templ: Template): Type = { val clazz = context.owner def checkParent(tpt: Tree): Type = { val tp = tpt.tpe @@ -437,33 +436,33 @@ trait Namers requires Analyzer { tp } } + def enterSelf(self: ValDef) { + if (!self.tpt.isEmpty) { + clazz.typeOfThis = selfTypeCompleter(self.tpt) + self.symbol = clazz.thisSym + } else { + self.tpt.tpe = NoType + if (self.name != nme.WILDCARD) { + clazz.typeOfThis = clazz.tpe + self.symbol = clazz.thisSym + } else { + self.symbol = clazz.newThisSym(self.pos) setInfo clazz.tpe + } + } + if (self.name != nme.WILDCARD) { + self.symbol.name = self.name + context.scope enter self.symbol + } + } val parents = typer.parentTypes(templ) map checkParent + enterSelf(templ.self) val decls = newDecls(templ, clazz) new Namer(context.make(templ, clazz, decls)).enterSyms(templ.body) ClassInfoType(parents, decls, clazz) } - private def classSig(tparams: List[AbsTypeDef], self: ValDef, impl: Template): Type = { - val clazz = context.owner - val tparamSyms = typer.reenterTypeParams(tparams) - if (!self.tpt.isEmpty) { - clazz.typeOfThis = selfTypeCompleter(self.tpt) - self.symbol = clazz.thisSym - } else { - self.tpt.tpe = NoType - if (self.name != nme.WILDCARD) { - clazz.typeOfThis = clazz.tpe - self.symbol = clazz.thisSym - } else { - self.symbol = clazz.newThisSym(self.pos) setInfo clazz.tpe - } - } - if (self.name != nme.WILDCARD) { - context.scope enter self.symbol - clazz.thisSym.name = self.name - } - parameterizedType(tparamSyms, templateSig(impl)) - } + private def classSig(tparams: List[AbsTypeDef], impl: Template): Type = + parameterizedType(typer.reenterTypeParams(tparams), templateSig(impl)) private def methodSig(tparams: List[AbsTypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree): Type = { @@ -658,12 +657,12 @@ trait Namers requires Analyzer { val result = try { tree match { - case ClassDef(_, _, tparams, self, impl) => - new Namer(makeNewScope(context, tree, sym)).classSig(tparams, self, impl) + case ClassDef(_, _, tparams, impl) => + new Namer(makeNewScope(context, tree, sym)).classSig(tparams, impl) case ModuleDef(_, _, impl) => val clazz = sym.moduleClass - clazz.setInfo(new Namer(context.make(tree, clazz)).templateSig(impl)); + clazz.setInfo(new Namer(makeNewScope(context, tree, clazz)).templateSig(impl)) //clazz.typeOfThis = singleType(sym.owner.thisType, sym); clazz.tpe; diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 295f040aae..2b5d898fa5 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -459,7 +459,7 @@ abstract class RefChecks extends InfoTransform { for (val stat <- stats) { index = index + 1; stat match { - case ClassDef(_, _, _, _, _) | DefDef(_, _, _, _, _, _) | ModuleDef(_, _, _) | ValDef(_, _, _, _) => + case ClassDef(_, _, _, _) | DefDef(_, _, _, _, _, _) | ModuleDef(_, _, _) | ValDef(_, _, _, _) => assert(stat.symbol != NoSymbol, stat);//debug if (stat.symbol.isLocal) { currentLevel.scope.enter(newScopeEntry(stat.symbol, currentLevel.scope)); @@ -563,7 +563,7 @@ abstract class RefChecks extends InfoTransform { def transformStat(tree: Tree, index: int): List[Tree] = tree match { case ModuleDef(mods, name, impl) => val sym = tree.symbol - val cdef = ClassDef(mods | MODULE, name, List(), emptyValDef, impl) + val cdef = ClassDef(mods | MODULE, name, List(), impl) .setPos(tree.pos) .setSymbol(sym.moduleClass) .setType(NoType); @@ -588,7 +588,7 @@ abstract class RefChecks extends InfoTransform { else transformTrees(List(cdef, vdef, ddef)) } - case ClassDef(_, _, _, _, _) if isConcreteLocalCaseFactory(tree.symbol) => + case ClassDef(_, _, _, _) if isConcreteLocalCaseFactory(tree.symbol) => val clazz = tree.symbol val factory = clazz.caseFactory if (factory == NoSymbol) { @@ -682,7 +682,7 @@ abstract class RefChecks extends InfoTransform { val sym = tree.symbol var result = tree tree match { - case ClassDef(mods, name, tparams, _, impl) => + case ClassDef(mods, name, tparams, impl) => validateVariance(sym, sym.info, CoVariance) validateVariance(sym, sym.typeOfThis, CoVariance) @@ -700,7 +700,7 @@ abstract class RefChecks extends InfoTransform { case AliasTypeDef(_, _, _, _) => validateVariance(sym, sym.info, CoVariance) - case Template(_, _) => + case Template(_, _, _) => localTyper = localTyper.atOwner(tree, currentOwner) validateBaseTypes(currentOwner) checkAllOverrides(currentOwner) diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index 0b88b7e340..2e1b250eee 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -51,7 +51,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT } override def transform(tree: Tree): Tree = tree match { - case ClassDef(_, _, _, _, _) => + case ClassDef(_, _, _, _) => val decls = tree.symbol.info.decls for (val sym <- decls.toList) { if (sym.privateWithin.isClass && !sym.privateWithin.isModuleClass && @@ -62,7 +62,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT } } super.transform(tree) - case Template(parents, body) => + case Template(parents, self, body) => val ownAccDefs = new ListBuffer[Tree]; accDefs = (currentOwner, ownAccDefs) :: accDefs; @@ -73,7 +73,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT curTree = tree val body1 = atOwner(currentOwner) { transformTrees(body) } accDefs = accDefs.tail; - copy.Template(tree, parents, ownAccDefs.toList ::: body1); + copy.Template(tree, parents, self, ownAccDefs.toList ::: body1); case Select(qual @ This(_), name) => val sym = tree.symbol diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index c395acc60b..1872642459 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -255,6 +255,6 @@ trait SyntheticMethods requires Analyzer { } val synthetics = ts.toList copy.Template( - templ, templ.parents, if (synthetics.isEmpty) templ.body else templ.body ::: synthetics) + templ, templ.parents, templ.self, if (synthetics.isEmpty) templ.body else templ.body ::: synthetics) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 4c8076d706..b71e17498a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -942,19 +942,11 @@ trait Typers requires Analyzer { val clazz = cdef.symbol reenterTypeParams(cdef.tparams) val tparams1 = List.mapConserve(cdef.tparams)(typedAbsTypeDef) - val self1 = cdef.self match { - case ValDef(mods, name, tpt, EmptyTree) => - val tpt1 = checkNoEscaping.privates(clazz.thisSym, typedType(tpt)) - copy.ValDef(cdef.self, mods, name, tpt1, EmptyTree) setType NoType - } - val implScope = newScope - if (self1.name != nme.WILDCARD) implScope enter self1.symbol - val impl1 = newTyper(context.make(cdef.impl, clazz, implScope)) + val impl1 = newTyper(context.make(cdef.impl, clazz, newTemplateScope(cdef.impl, clazz))) .typedTemplate(cdef.impl, parentTypes(cdef.impl)) val impl2 = addSyntheticMethods(impl1, clazz, context.unit) - val ret = copy.ClassDef(cdef, cdef.mods, cdef.name, tparams1, self1, impl2) + copy.ClassDef(cdef, cdef.mods, cdef.name, tparams1, impl2) .setType(NoType) - ret } /** @@ -1042,6 +1034,12 @@ trait Typers requires Analyzer { val clazz = context.owner if (templ.symbol == NoSymbol) templ setSymbol clazz.newLocalDummy(templ.pos) + val self1 = templ.self match { + case vd @ ValDef(mods, name, tpt, EmptyTree) => + val tpt1 = checkNoEscaping.privates(clazz.thisSym, typedType(tpt)) + copy.ValDef(vd, mods, name, tpt1, EmptyTree) setType NoType + } + if (self1.name != nme.WILDCARD) context.scope enter self1.symbol val selfType = if (clazz.isAnonymousClass && !phase.erasedTypes) intersectionType(clazz.info.parents, clazz.owner) @@ -1056,7 +1054,7 @@ trait Typers requires Analyzer { templ.body flatMap addGetterSetter else templ.body val body1 = typedStats(body, templ.symbol) - copy.Template(templ, parents1, body1) setType clazz.tpe + copy.Template(templ, parents1, self1, body1) setType clazz.tpe } /** @@ -2411,11 +2409,11 @@ trait Typers requires Analyzer { .typedStats(stats, NoSymbol) copy.PackageDef(tree, name, stats1) setType NoType - case tree @ ClassDef(_, _, _, _, _) => + case tree @ ClassDef(_, _, _, _) => newTyper(makeNewScope(context, tree, sym)).typedClassDef(tree) case tree @ ModuleDef(_, _, _) => - newTyper(context.make(tree, sym.moduleClass)).typedModuleDef(tree) + newTyper(makeNewScope(context, tree, sym.moduleClass)).typedModuleDef(tree) case vdef @ ValDef(_, _, _, _) => typedValDef(vdef) |