diff options
author | Paul Phillips <paulp@improving.org> | 2011-01-01 22:46:59 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-01-01 22:46:59 +0000 |
commit | 533ffe9482c530489ad4f6670831b8d87f78193a (patch) | |
tree | 567660ba8ee7f97e283154acdb84e0215195d8ed | |
parent | 03f90c173445e5d988f2e2199026901b4def45b8 (diff) | |
download | scala-533ffe9482c530489ad4f6670831b8d87f78193a.tar.gz scala-533ffe9482c530489ad4f6670831b8d87f78193a.tar.bz2 scala-533ffe9482c530489ad4f6670831b8d87f78193a.zip |
Removed the Name => TypeName implicit conversion.
questions start to arise as the ability to distinguish between type and
term names becomes more fully realized: particularly that the ability
to distinguish between TermSymbols and TypeSymbols has not come along
with the names. In any case, this is more tedious than I might have
anticipated but mostly because it's blazing a trail of typiness to ease
the path for others. No review.
17 files changed, 112 insertions, 117 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala index 686adc1800..55dfb07c54 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala @@ -153,7 +153,7 @@ abstract class TreeGen { stabilize(mkAttributedRef(sym)) def mkAttributedThis(sym: Symbol): Tree = - This(sym.name) setSymbol sym setType sym.thisType + This(sym.name.toTypeName) setSymbol sym setType sym.thisType def mkAttributedIdent(sym: Symbol): Tree = Ident(sym.name) setSymbol sym setType sym.tpe @@ -372,7 +372,7 @@ abstract class TreeGen { /** Try to convert Select(qual, name) to a SelectFromTypeTree. */ def convertToSelectFromType(qual: Tree, origName: Name) = convertToTypeName(qual) match { - case Some(qual1) => SelectFromTypeTree(qual1 setPos qual.pos, origName) + case Some(qual1) => SelectFromTypeTree(qual1 setPos qual.pos, origName.toTypeName) case _ => EmptyTree } diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index f6434b1662..7f52d40053 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -119,7 +119,7 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable => def ClassDef(sym: Symbol, impl: Template): ClassDef = atPos(sym.pos) { ClassDef(Modifiers(sym.flags), - sym.name, + sym.name.toTypeName, sym.typeParams map TypeDef, impl) setSymbol sym } @@ -192,7 +192,7 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable => /** A TypeDef node which defines given `sym' with given tight hand side `rhs'. */ def TypeDef(sym: Symbol, rhs: Tree): TypeDef = atPos(sym.pos) { - TypeDef(Modifiers(sym.flags), sym.name, sym.typeParams map TypeDef, rhs) setSymbol sym + TypeDef(Modifiers(sym.flags), sym.name.toTypeName, sym.typeParams map TypeDef, rhs) setSymbol sym } /** A TypeDef node which defines abstract type or type parameter for given `sym' */ @@ -288,9 +288,9 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable => (superRef /: argss) (Apply) } - def Super(sym: Symbol, mix: Name): Tree = Super(sym.name, mix) setSymbol sym + def Super(sym: Symbol, mix: Name): Tree = Super(sym.name.toTypeName, mix.toTypeName) setSymbol sym - def This(sym: Symbol): Tree = This(sym.name) setSymbol sym + def This(sym: Symbol): Tree = This(sym.name.toTypeName) setSymbol sym def Select(qualifier: Tree, sym: Symbol): Select = Select(qualifier, sym.name) setSymbol sym @@ -406,7 +406,7 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable => class StrictTreeCopier extends TreeCopier { def ClassDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], impl: Template) = - new ClassDef(mods, name, tparams, impl).copyAttrs(tree) + new ClassDef(mods, name.toTypeName, tparams, impl).copyAttrs(tree) def PackageDef(tree: Tree, pid: RefTree, stats: List[Tree]) = new PackageDef(pid, stats).copyAttrs(tree) def ModuleDef(tree: Tree, mods: Modifiers, name: Name, impl: Template) = @@ -416,7 +416,7 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable => def DefDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) = new DefDef(mods, name, tparams, vparamss, tpt, rhs).copyAttrs(tree) def TypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[TypeDef], rhs: Tree) = - new TypeDef(mods, name, tparams, rhs).copyAttrs(tree) + new TypeDef(mods, name.toTypeName, tparams, rhs).copyAttrs(tree) def LabelDef(tree: Tree, name: Name, params: List[Ident], rhs: Tree) = new LabelDef(name, params, rhs).copyAttrs(tree) def Import(tree: Tree, expr: Tree, selectors: List[ImportSelector]) = @@ -470,9 +470,9 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable => def ApplyDynamic(tree: Tree, qual: Tree, args: List[Tree]) = new ApplyDynamic(qual, args).copyAttrs(tree) def Super(tree: Tree, qual: Name, mix: Name) = - new Super(qual, mix).copyAttrs(tree) + new Super(qual.toTypeName, mix.toTypeName).copyAttrs(tree) def This(tree: Tree, qual: Name) = - new This(qual).copyAttrs(tree) + new This(qual.toTypeName).copyAttrs(tree) def Select(tree: Tree, qualifier: Tree, selector: Name) = new Select(qualifier, selector).copyAttrs(tree) def Ident(tree: Tree, name: Name) = @@ -489,7 +489,7 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable => def SingletonTypeTree(tree: Tree, ref: Tree) = new SingletonTypeTree(ref).copyAttrs(tree) def SelectFromTypeTree(tree: Tree, qualifier: Tree, selector: Name) = - new SelectFromTypeTree(qualifier, selector).copyAttrs(tree) + new SelectFromTypeTree(qualifier, selector.toTypeName).copyAttrs(tree) def CompoundTypeTree(tree: Tree, templ: Template) = new CompoundTypeTree(templ).copyAttrs(tree) def AppliedTypeTree(tree: Tree, tpt: Tree, args: List[Tree]) = diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index 9742d7e905..7c07a98494 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -18,6 +18,8 @@ abstract class TreeBuilder { import global._ def freshName(): Name = freshName("x$") + def freshTermName(): TermName = freshTermName("x$") + def freshName(prefix: String): Name def freshTermName(prefix: String): TermName def freshTypeName(prefix: String): TypeName @@ -184,7 +186,7 @@ abstract class TreeBuilder { if (treeInfo.isLeftAssoc(op)) { Apply(atPos(opPos union left.pos) { Select(stripParens(left), op.encode) }, arguments) } else { - val x = freshName() + val x = freshTermName() Block( List(ValDef(Modifiers(SYNTHETIC), x, TypeTree(), stripParens(left))), Apply(atPos(opPos union right.pos) { Select(stripParens(right), op.encode) }, List(Ident(x)))) @@ -355,7 +357,7 @@ abstract class TreeBuilder { matchVarPattern(pat) match { case Some((name, tpt)) => Function( - List(atPos(pat.pos) { ValDef(Modifiers(PARAM), name, tpt, EmptyTree) }), + List(atPos(pat.pos) { ValDef(Modifiers(PARAM), name.toTermName, tpt, EmptyTree) }), body) setPos splitpos case None => atPos(splitpos) { @@ -472,7 +474,7 @@ abstract class TreeBuilder { /** Create visitor <x => x match cases> */ def makeVisitor(cases: List[CaseDef], checkExhaustive: Boolean, prefix: String): Tree = { - val x = freshName(prefix) + val x = freshTermName(prefix) val id = Ident(x) val sel = if (checkExhaustive) id else makeUnchecked(id) Function(List(makeSyntheticParam(x)), Match(sel, cases)) @@ -525,7 +527,7 @@ abstract class TreeBuilder { def makeSequencedMatch(selector: Tree, cases: List[CaseDef]): Tree = { require(cases.nonEmpty) - val selectorName = freshName() + val selectorName = freshTermName() val valdef = atPos(selector.pos)(ValDef(Modifiers(PRIVATE | LOCAL | SYNTHETIC), selectorName, TypeTree(), selector)) val nselector = Ident(selectorName) @@ -543,7 +545,7 @@ abstract class TreeBuilder { def makePatDef(mods: Modifiers, pat: Tree, rhs: Tree): List[Tree] = matchVarPattern(pat) match { case Some((name, tpt)) => List(atPos(pat.pos union rhs.pos) { - ValDef(mods, name, tpt, rhs) + ValDef(mods, name.toTermName, tpt, rhs) }) case None => @@ -569,10 +571,10 @@ abstract class TreeBuilder { vars match { case List((vname, tpt, pos)) => List(atPos(pat.pos union pos union rhs.pos) { - ValDef(mods, vname, tpt, matchExpr) + ValDef(mods, vname.toTermName, tpt, matchExpr) }) case _ => - val tmp = freshName() + val tmp = freshTermName() val firstDef = atPos(matchExpr.pos) { ValDef(Modifiers(PRIVATE | LOCAL | SYNTHETIC | (mods.flags & LAZY)), @@ -581,7 +583,7 @@ abstract class TreeBuilder { var cnt = 0 val restDefs = for ((vname, tpt, pos) <- vars) yield atPos(pos) { cnt = cnt + 1 - ValDef(mods, vname, tpt, Select(Ident(tmp), newTermName("_" + cnt))) + ValDef(mods, vname.toTermName, tpt, Select(Ident(tmp), newTermName("_" + cnt))) } firstDef :: restDefs } @@ -596,7 +598,7 @@ abstract class TreeBuilder { if (contextBounds.isEmpty) vparamss else { val mods = Modifiers(if (owner.isTypeName) PARAMACCESSOR | LOCAL | PRIVATE else PARAM) - def makeEvidenceParam(tpt: Tree) = ValDef(mods | IMPLICIT, freshName(nme.EVIDENCE_PARAM_PREFIX), tpt, EmptyTree) + def makeEvidenceParam(tpt: Tree) = ValDef(mods | IMPLICIT, freshTermName(nme.EVIDENCE_PARAM_PREFIX), tpt, EmptyTree) vparamss ::: List(contextBounds map makeEvidenceParam) } diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala index d4167998e5..aed29f6130 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala @@ -898,7 +898,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { Ident(nme.EMPTY_PACKAGE_NAME) } thisPackageName = gen.convertToTypeName(pkg) match { - case Some(t) => t.name + case Some(t) => t.name.toTypeName case _ => tpnme.EMPTY } val buf = new ListBuffer[Tree] diff --git a/src/compiler/scala/tools/nsc/symtab/NameManglers.scala b/src/compiler/scala/tools/nsc/symtab/NameManglers.scala index 37f65fd348..daaad94387 100644 --- a/src/compiler/scala/tools/nsc/symtab/NameManglers.scala +++ b/src/compiler/scala/tools/nsc/symtab/NameManglers.scala @@ -45,7 +45,7 @@ trait NameManglers { /** The expanded setter name of `name' relative to this class `base` */ - def expandedSetterName(name: Name, base: Symbol): Name = + def expandedSetterName(name: TermName, base: Symbol): TermName = expandedName(name, base, separator = TRAIT_SETTER_SEPARATOR_STRING) /** If `name' is an expandedName name, the original name. @@ -80,20 +80,20 @@ trait NameManglers { } else (name, "", "") - def getterName(name: Name): Name = if (isLocalName(name)) localToGetter(name) else name - def getterToLocal(name: Name): Name = name append LOCAL_SUFFIX_STRING - def getterToSetter(name: Name): Name = name append SETTER_SUFFIX - def localToGetter(name: Name): Name = name stripEnd LOCAL_SUFFIX_STRING + def getterName(name: TermName): TermName = if (isLocalName(name)) localToGetter(name) else name + def getterToLocal(name: TermName): TermName = name.toTermName append LOCAL_SUFFIX_STRING + def getterToSetter(name: TermName): TermName = name.toTermName append SETTER_SUFFIX + def localToGetter(name: TermName): TermName = name stripEnd LOCAL_SUFFIX_STRING toTermName - def setterToGetter(name: Name): Name = { + def setterToGetter(name: TermName): TermName = { val p = name.pos(TRAIT_SETTER_SEPARATOR_STRING) if (p < name.length) setterToGetter(name.subName(p + TRAIT_SETTER_SEPARATOR_STRING.length, name.length)) else - name stripEnd SETTER_SUFFIX + name stripEnd SETTER_SUFFIX toTermName } - def defaultGetterName(name: Name, pos: Int): Name = { + def defaultGetterName(name: Name, pos: Int): TermName = { val prefix = if (isConstructorName(name)) "init" else name newTermName(prefix + DEFAULT_GETTER_STRING + pos) } diff --git a/src/compiler/scala/tools/nsc/symtab/Names.scala b/src/compiler/scala/tools/nsc/symtab/Names.scala index c794aadd62..0daf711d4b 100644 --- a/src/compiler/scala/tools/nsc/symtab/Names.scala +++ b/src/compiler/scala/tools/nsc/symtab/Names.scala @@ -35,11 +35,11 @@ trait Names extends reflect.generic.Names { /** hashtable for finding term names quickly */ - private val termHashtable = new Array[Name](HASH_SIZE) + private val termHashtable = new Array[TermName](HASH_SIZE) /** hashtable for finding type names quickly */ - private val typeHashtable = new Array[Name](HASH_SIZE) + private val typeHashtable = new Array[TypeName](HASH_SIZE) /** the hashcode of a name */ @@ -145,26 +145,16 @@ trait Names extends reflect.generic.Names { def nameChars: Array[Char] = chrs @deprecated("") def view(s: String): TermName = newTermName(s) - override def onNameTranslate(name: Name): Unit = { - if (nameDebug) { - Console println "Translating %s '%s' to %s.".format( - if (isTypeName(name)) "type" else "term", - name, - if (isTypeName(name)) "term" else "type" - ) - } - } - // Classes ---------------------------------------------------------------------- /** The name class. */ - abstract class Name(index: Int, len: Int) extends Function1[Int, Char] { + sealed abstract class Name(index: Int, len: Int) extends Function1[Int, Char] { /** Index into name table */ def start: Int = index /** next name in the same hash bucket */ - var next: Name = null + def next: Name /** return the length of this name */ @@ -399,12 +389,8 @@ trait Names extends reflect.generic.Names { else newTermName(res) } - def append(suffix: String): Name = { - val chars = this + suffix - if (isTypeName) newTypeName(chars) - else newTermName(chars) - } - def append(suffix: Name): Name = append(suffix.toString) + def append(suffix: String): Name + def append(suffix: Name): Name /** Replace $op_name by corresponding operator symbol. */ @@ -416,7 +402,7 @@ trait Names extends reflect.generic.Names { } final class TermName(index: Int, len: Int, hash: Int) extends Name(index, len) { - next = termHashtable(hash) + var next: TermName = termHashtable(hash) termHashtable(hash) = this def isTermName: Boolean = true def isTypeName: Boolean = false @@ -430,13 +416,15 @@ trait Names extends reflect.generic.Names { n = new TypeName(index, len, h); n } + def append(suffix: String): TermName = newTermName(this + suffix) + def append(suffix: Name): TermName = append(suffix.toString) def companionName: TypeName = toTypeName def subName(from: Int, to: Int): TermName = newTermName(chrs, start + from, to - from) } final class TypeName(index: Int, len: Int, hash: Int) extends Name(index, len) { - next = typeHashtable(hash) + var next: TypeName = typeHashtable(hash) typeHashtable(hash) = this def isTermName: Boolean = false def isTypeName: Boolean = true @@ -450,6 +438,9 @@ trait Names extends reflect.generic.Names { n } def toTypeName: TypeName = this + + def append(suffix: String): TypeName = newTypeName(this + suffix) + def append(suffix: Name): TypeName = append(suffix.toString) def companionName: TermName = toTermName def subName(from: Int, to: Int): TypeName = newTypeName(chrs, start + from, to - from) diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 43dc2b768b..b94bbc81b7 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -234,7 +234,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => * body of the method, there's a local copy of `T' which is a TypeSkolem. */ final def newTypeSkolem: Symbol = - new TypeSkolem(owner, pos, name, this) + new TypeSkolem(owner, pos, name.toTypeName, this) .setFlag(flags) final def newClass(pos: Position, name: TypeName) = @@ -272,9 +272,10 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => clazz } - final def newErrorSymbol(name: Name): Symbol = - if (name.isTypeName) newErrorClass(name) - else newErrorValue(name) + final def newErrorSymbol(name: Name): Symbol = name match { + case x: TypeName => newErrorClass(x) + case x: TermName => newErrorValue(x) + } // Locking and unlocking ------------------------------------------------------ @@ -927,7 +928,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => oldsymbuf += sym newsymbuf += ( if (sym.isClass) - tp.typeSymbol.newAbstractType(sym.pos, sym.name).setInfo(sym.existentialBound) + tp.typeSymbol.newAbstractType(sym.pos, sym.name.toTypeName).setInfo(sym.existentialBound) else sym.cloneSymbol(tp.typeSymbol)) } @@ -1652,6 +1653,8 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => class TermSymbol(initOwner: Symbol, initPos: Position, initName: TermName) extends Symbol(initOwner, initPos, initName) { final override def isTerm = true + + override def name: TermName = super.name privateWithin = NoSymbol var referenced: Symbol = NoSymbol @@ -1796,6 +1799,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => private var tpeCache: Type = _ private var tpePeriod = NoPeriod + override def name: TypeName = super.name.asInstanceOf[TypeName] final override def isType = true override def isNonClassType = true override def isAbstractType = isDeferred @@ -1874,7 +1878,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => } def cloneSymbolImpl(owner: Symbol): Symbol = - new TypeSymbol(owner, pos, name) + new TypeSymbol(owner, pos, name) //.toTypeName) incCounter(typeSymbolCount) } @@ -1956,7 +1960,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => } flatname } - else rawname + else rawname.asInstanceOf[TypeName] private var thisTypeCache: Type = _ private var thisTypePeriod = NoPeriod @@ -2061,14 +2065,14 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => override def originalEnclosingMethod = this } - def cloneSymbols(syms: List[Symbol]): List[Symbol] = { - val syms1 = syms map (_.cloneSymbol) + def cloneSymbols[T <: Symbol](syms: List[T]): List[T] = { + val syms1 = syms map (_.cloneSymbol.asInstanceOf[T]) for (sym1 <- syms1) sym1.setInfo(sym1.info.substSym(syms, syms1)) syms1 } - def cloneSymbols(syms: List[Symbol], owner: Symbol): List[Symbol] = { - val syms1 = syms map (_.cloneSymbol(owner)) + def cloneSymbols[T <: Symbol](syms: List[T], owner: Symbol): List[T] = { + val syms1 = syms map (_.cloneSymbol(owner).asInstanceOf[T]) for (sym1 <- syms1) sym1.setInfo(sym1.info.substSym(syms, syms1)) syms1 } diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index b9d172728d..d5a59d8a9c 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -2135,7 +2135,7 @@ A type's typeSymbol should never be inspected directly. def mkSkolem(tparam: Symbol): Symbol = { val skolem = new TypeSkolem( if (owner == NoSymbol) tparam.owner else owner, - tparam.pos, tparam.name, origin) + tparam.pos, tparam.name.toTypeName, origin) skolem.setInfo(tparam.info.cloneInfo(skolem)) .setFlag(tparam.flags | EXISTENTIAL) .resetFlag(PARAM) @@ -2416,7 +2416,7 @@ A type's typeSymbol should never be inspected directly. */ def registerTypeSelection(sym: Symbol, tp: Type): Boolean = { val bound = refinedType(List(WildcardType), NoSymbol) - val bsym = bound.typeSymbol.newAliasType(NoPosition, sym.name) + val bsym = bound.typeSymbol.newAliasType(NoPosition, sym.name.toTypeName) bsym setInfo tp bound.decls enter bsym registerBound(bound, false) @@ -5120,7 +5120,7 @@ A type's typeSymbol should never be inspected directly. else { def lubBounds(bnds: List[TypeBounds]): TypeBounds = TypeBounds(glb(bnds map (_.lo), decr(depth)), lub(bnds map (_.hi), decr(depth))) - lubRefined.typeSymbol.newAbstractType(proto.pos, proto.name) + lubRefined.typeSymbol.newAbstractType(proto.pos, proto.name.toTypeName) .setInfoOwnerAdjusted(lubBounds(symtypes map (_.bounds))) } } diff --git a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala b/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala index ce519b4ca4..3489b3cb65 100644 --- a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala @@ -150,8 +150,8 @@ abstract class TypeParser { val canBeTakenAddressOf = (typ.IsValueType || typ.IsEnum) && (typ.FullName != "System.Enum") if(canBeTakenAddressOf) { - clazzBoxed = clazz.owner.newClass(clazz.name append "Boxed") - clazzMgdPtr = clazz.owner.newClass(clazz.name append "MgdPtr") + clazzBoxed = clazz.owner.newClass(clazz.name.toTypeName append "Boxed") + clazzMgdPtr = clazz.owner.newClass(clazz.name.toTypeName append "MgdPtr") clrTypes.mdgptrcls4clssym(clazz) = clazzMgdPtr /* adding typMgdPtr to clrTypes.sym2type should happen early (before metadata for supertypes is parsed, before metadata for members are parsed) so that clazzMgdPtr can be found by getClRType. */ diff --git a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala index df3a82defd..093ff42fe0 100644 --- a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala +++ b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala @@ -69,7 +69,7 @@ trait EtaExpansion { self: Analyzer => val vname: Name = freshName() // Problem with ticket #2351 here defs += atPos(tree.pos) { - ValDef(Modifiers(SYNTHETIC), vname, TypeTree(), tree) + ValDef(Modifiers(SYNTHETIC), vname.toTermName, TypeTree(), tree) } Ident(vname) setPos tree.pos.focus } @@ -103,7 +103,7 @@ trait EtaExpansion { self: Analyzer => case mt @ MethodType(paramSyms, restpe) if !mt.isImplicit => val params = paramSyms map (sym => ValDef(Modifiers(SYNTHETIC | PARAM), - sym.name, TypeTree(sym.tpe) , EmptyTree)) + sym.name.toTermName, TypeTree(sym.tpe) , EmptyTree)) atPos(tree.pos.makeTransparent) { Function(params, expand(Apply(tree, params map gen.paramToArg), restpe)) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 7bf1e8e0df..6e4efacb39 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -149,8 +149,10 @@ self: Analyzer => */ def memberWildcardType(name: Name, tp: Type) = { val result = refinedType(List(WildcardType), NoSymbol) - var psym = if (name.isTypeName) result.typeSymbol.newAbstractType(NoPosition, name) - else result.typeSymbol.newValue(NoPosition, name) + var psym = name match { + case x: TypeName => result.typeSymbol.newAbstractType(NoPosition, x) + case x: TermName => result.typeSymbol.newValue(NoPosition, x) + } psym setInfo tp result.decls enter psym result diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 072bda9097..5e03c048c7 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -189,7 +189,7 @@ trait Namers { self: Analyzer => } var pkg = owner.info.decls.lookup(pid.name) if (!pkg.isPackage || owner != pkg.owner) { - pkg = owner.newPackage(pos, pid.name) + pkg = owner.newPackage(pos, pid.name.toTermName) pkg.moduleClass.setInfo(new PackageClassInfoType(new Scope, pkg.moduleClass)) pkg.setInfo(pkg.moduleClass.tpe) enterInScope(pkg, owner.info.decls) @@ -466,7 +466,7 @@ trait Namers { self: Analyzer => } def enterNewMethod(tree: Tree, name: Name, flags: Long, mods: Modifiers, pos: Position): TermSymbol = { - val sym = context.owner.newMethod(pos, name).setFlag(flags) + val sym = context.owner.newMethod(pos, name.toTermName).setFlag(flags) setPrivateWithin(tree, sym, mods) enterInScope(sym) sym @@ -504,7 +504,7 @@ trait Namers { self: Analyzer => val beanGetterDef = atPos(vd.pos.focus) { DefDef(getterMods, getterName, Nil, List(Nil), tpt.duplicate, if (mods.isDeferred) EmptyTree - else Select(This(getter.owner.name), name)) } + else Select(This(getter.owner.name.toTypeName), name)) } enterSyntheticSym(beanGetterDef) if (mods.isMutable) { @@ -1350,7 +1350,7 @@ trait Namers { self: Analyzer => if (member.hasAccessorFlag) { if (member.isDeferred) { val getter = if (member.isSetter) member.getter(member.owner) else member - val result = getter.owner.newValue(getter.pos, getter.name) + val result = getter.owner.newValue(getter.pos, getter.name.toTermName) .setInfo(getter.tpe.resultType) .setFlag(DEFERRED) if (getter.setter(member.owner) != NoSymbol) result.setFlag(MUTABLE) diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 67664b7262..adc7813b9c 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -58,7 +58,7 @@ abstract class RefChecks extends InfoTransform { sym setFlag (lateMETHOD | STABLE) if (isNestedModule) { - val moduleVar = sym.owner.info.decl(nme.moduleVarName(sym.name)) + val moduleVar = sym.owner.info.decl(nme.moduleVarName(sym.name.toTermName)) if (moduleVar == NoSymbol) { val tree = gen.mkModuleVarDef(sym) tree.symbol.setInfo(tp) @@ -1004,7 +1004,7 @@ abstract class RefChecks extends InfoTransform { val cdef = mkClassDef(false) if (!sym.allOverriddenSymbols.isEmpty) { - val factory = sym.owner.newMethod(sym.pos, sym.name) + val factory = sym.owner.newMethod(sym.pos, sym.name.toTermName) .setFlag(sym.flags | STABLE).resetFlag(MODULE) .setInfo(PolyType(List(), sym.moduleClass.tpe)) sym.owner.info.decls.enter(factory) @@ -1029,7 +1029,7 @@ abstract class RefChecks extends InfoTransform { if (!transformedInfo) gen.mkModuleVarDef(sym) else { - val vsym0 = sym.owner.info.decl(nme.moduleVarName(sym.name)) + val vsym0 = sym.owner.info.decl(nme.moduleVarName(sym.name.toTermName)) // In case we are dealing with local symbol then we already have correct error with forward reference ValDef(if (vsym0 == NoSymbol) gen.mkModuleVarDef(sym).symbol else vsym0, EmptyTree) } diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index d7a0ce0544..2d544ba1d1 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -70,7 +70,7 @@ trait SyntheticMethods extends ast.TreeDSL { newSyntheticMethod(name, flags | OVERRIDE, tpeCons) def newSyntheticMethod(name: Name, flags: Int, tpeCons: Symbol => Type) = { - val method = clazz.newMethod(clazz.pos.focus, name) setFlag flags + val method = clazz.newMethod(clazz.pos.focus, name.toTermName) setFlag flags createdMethodSymbols += method method setInfo tpeCons(method) clazz.info.decls.enter(method) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index b5771d772f..5ce685ed73 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -12,8 +12,9 @@ package scala.tools.nsc package typechecker -import scala.collection.mutable.{ HashMap, ListBuffer } +import scala.collection.{ mutable, immutable } import scala.tools.nsc.util.BatchSourceFile +import mutable.ListBuffer import symtab.Flags._ import util.Statistics @@ -39,7 +40,7 @@ trait Typers extends Modes { // namer calls typer.computeType(rhs) on DefDef / ValDef when tpt is empty. the result // is cached here and re-used in typedDefDef / typedValDef // Also used to cache imports type-checked by namer. - val transformed = new HashMap[Tree, Tree] + val transformed = new mutable.HashMap[Tree, Tree] final val shortenImports = false @@ -1620,7 +1621,7 @@ trait Typers extends Modes { case Some(repl) => silent(_.typedTypeConstructor(stringParser(repl).typ())) match { case tpt: Tree => - val alias = enclClass.newAliasType(useCase.pos, name) + val alias = enclClass.newAliasType(useCase.pos, name.toTypeName) val tparams = cloneSymbols(tpt.tpe.typeSymbol.typeParams, alias) alias setInfo polyType(tparams, appliedType(tpt.tpe, tparams map (_.tpe))) context.scope.enter(alias) @@ -1631,7 +1632,7 @@ trait Typers extends Modes { } for (tree <- trees; t <- tree) t match { - case Ident(name) if (name.length > 0 && name(0) == '$') => defineAlias(name) + case Ident(name) if name startsWith '$' => defineAlias(name) case _ => } useCase.aliases = context.scope.toList @@ -2446,13 +2447,13 @@ trait Typers extends Modes { //Console.println("UNAPP: need to typetest, arg.tpe = "+arg.tpe+", unappType = "+unappType) def freshArgType(tp: Type): (Type, List[Symbol]) = tp match { case MethodType(params, _) => - (params(0).tpe, List()) + (params(0).tpe, Nil) case PolyType(tparams, restype) => val tparams1 = cloneSymbols(tparams) (freshArgType(restype)._1.substSym(tparams, tparams1), tparams1) case OverloadedType(_, _) => error(fun.pos, "cannot resolve overloaded unapply") - (ErrorType, List()) + (ErrorType, Nil) } val (unappFormal, freeVars) = freshArgType(unappType.skolemizeExistential(context.owner, tree)) val context1 = context.makeNewScope(context.tree, context.owner) @@ -2462,7 +2463,7 @@ trait Typers extends Modes { // turn any unresolved type variables in freevars into existential skolems val skolems = freeVars map { fv => - val skolem = new TypeSkolem(context1.owner, fun.pos, fv.name, fv) + val skolem = new TypeSkolem(context1.owner, fun.pos, fv.name.toTypeName, fv) skolem.setInfo(fv.info.cloneInfo(skolem)) .setFlag(fv.flags | EXISTENTIAL).resetFlag(PARAM) skolem @@ -2725,7 +2726,10 @@ trait Typers extends Modes { */ protected def existentialTransform(rawSyms: List[Symbol], tp: Type) = { val typeParams: List[Symbol] = rawSyms map { sym => - val name = if (sym.isType) sym.name else newTypeName(sym.name+".type") + val name = sym.name match { + case x: TypeName => x + case x => newTypeName(x+".type") + } val bound = sym.existentialBound val sowner = if (isRawParameter(sym)) context.owner else sym.owner val quantified: Symbol = sowner.newAbstractType(sym.pos, name).setFlag(EXISTENTIAL) @@ -2985,7 +2989,7 @@ trait Typers extends Modes { def typedBind(name: Name, body: Tree) = { var vble = tree.symbol - if (name.isTypeName) { + def typedBindType(name: TypeName) = { assert(body == EmptyTree, context.unit + " typedBind: " + name.debugString + " " + body + " " + body.getClass) if (vble == NoSymbol) vble = @@ -2998,7 +3002,8 @@ trait Typers extends Modes { vble = if (vble.name == tpnme.WILDCARD) context.scope.enter(vble) else namer.enterInScope(vble) tree setSymbol vble setType vble.tpe - } else { + } + def typedBindTerm(name: TermName) = { if (vble == NoSymbol) vble = context.owner.newValue(tree.pos, name) if (vble.name.toTermName != nme.WILDCARD) { @@ -3012,6 +3017,10 @@ trait Typers extends Modes { else body1.tpe) treeCopy.Bind(tree, name, body1) setSymbol vble setType body1.tpe // burak, was: pt } + name match { + case x: TypeName => typedBindType(x) + case x: TermName => typedBindTerm(x) + } } def typedArrayValue(elemtpt: Tree, elems: List[Tree]) = { @@ -3042,7 +3051,7 @@ trait Typers extends Modes { if (treeInfo.mayBeVarGetter(varsym)) { lhs1 match { case Select(qual, name) => - val sel = Select(qual, nme.getterToSetter(name)) setPos lhs.pos + val sel = Select(qual, nme.getterToSetter(name.toTermName)) setPos lhs.pos val app = Apply(sel, List(rhs)) setPos tree.pos return typed(app, mode, pt) diff --git a/src/library/scala/reflect/generic/Names.scala b/src/library/scala/reflect/generic/Names.scala index 8ec05684d1..90c38c04b3 100755 --- a/src/library/scala/reflect/generic/Names.scala +++ b/src/library/scala/reflect/generic/Names.scala @@ -19,22 +19,6 @@ trait Names { def isTermName(name: Name): Boolean def isTypeName(name: Name): Boolean - /** These should come out before 2.9 ships, but they have to be - * in the library to reach a few bits like the unpickler. - */ - def onNameTranslate(name: Name): Unit = () - implicit def promoteTypeNamesAsNecessary(name: Name): TypeName = { - if (isTermName(name)) - onNameTranslate(name) - - mkTypeName(name) - } - implicit def promoteTermNamesAsNecessary(name: Name): TermName = { - if (isTypeName(name)) - onNameTranslate(name) - - mkTermName(name) - } + implicit def promoteTermNamesAsNecessary(name: Name): TermName = mkTermName(name) } - diff --git a/src/library/scala/reflect/generic/UnPickler.scala b/src/library/scala/reflect/generic/UnPickler.scala index b7b06a51f4..7b7c34a767 100755 --- a/src/library/scala/reflect/generic/UnPickler.scala +++ b/src/library/scala/reflect/generic/UnPickler.scala @@ -267,14 +267,14 @@ abstract class UnPickler { } finishSym(tag match { - case TYPEsym => owner.newAbstractType(name) - case ALIASsym => owner.newAliasType(name) + case TYPEsym => owner.newAbstractType(mkTypeName(name)) + case ALIASsym => owner.newAliasType(mkTypeName(name)) case CLASSsym => val sym = (isClassRoot, isModuleFlag) match { case (true, true) => moduleRoot.moduleClass case (true, false) => classRoot - case (false, true) => owner.newModuleClass(name) - case (false, false) => owner.newClass(name) + case (false, true) => owner.newModuleClass(mkTypeName(name)) + case (false, false) => owner.newClass(mkTypeName(name)) } if (!atEnd) sym.typeOfThis = newLazyTypeRef(readNat()) @@ -510,7 +510,7 @@ abstract class UnPickler { setSymModsName() val impl = readTemplateRef() val tparams = until(end, readTypeDefRef) - ClassDef(mods, name, tparams, impl) + ClassDef(mods, mkTypeName(name), tparams, impl) case MODULEtree => setSymModsName() @@ -534,7 +534,7 @@ abstract class UnPickler { setSymModsName() val rhs = readTreeRef() val tparams = until(end, readTypeDefRef) - TypeDef(mods, name, tparams, rhs) + TypeDef(mods, mkTypeName(name), tparams, rhs) case LABELtree => setSymName() @@ -657,13 +657,13 @@ abstract class UnPickler { case SUPERtree => setSym() - val qual = readNameRef() - val mix = readNameRef() + val qual = readTypeNameRef() + val mix = readTypeNameRef() Super(qual, mix) case THIStree => setSym() - This(readNameRef()) + This(readTypeNameRef()) case SELECTtree => setSym() @@ -691,7 +691,7 @@ abstract class UnPickler { case SELECTFROMTYPEtree => val qualifier = readTreeRef() - val selector = readNameRef() + val selector = readTypeNameRef() SelectFromTypeTree(qualifier, selector) case COMPOUNDTYPEtree => @@ -745,6 +745,9 @@ abstract class UnPickler { protected def readModifiersRef(): Modifiers = at(readNat(), readModifiers) protected def readTreeRef(): Tree = at(readNat(), readTree) + protected def readTypeNameRef(): TypeName = mkTypeName(readNameRef()) + protected def readTermNameRef(): TermName = mkTermName(readNameRef()) + protected def readTemplateRef(): Template = readTreeRef() match { case templ:Template => templ |