summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-12-03 23:53:58 +0000
committerPaul Phillips <paulp@improving.org>2010-12-03 23:53:58 +0000
commit9e9914e109c91cd4f86802129c236827517d8386 (patch)
tree7cb656bc2b54f13e53b2d55db59c10c418296c77
parente1a0866ce748ee1a228060f401dbb190d3caa8c3 (diff)
downloadscala-9e9914e109c91cd4f86802129c236827517d8386.tar.gz
scala-9e9914e109c91cd4f86802129c236827517d8386.tar.bz2
scala-9e9914e109c91cd4f86802129c236827517d8386.zip
Starting the mopping up now that names have som...
Starting the mopping up now that names have some more sense of their place in the universe. Cleaned up some heavy multi-boolean logic. Added more documentation on the relationships between entities in Symbols and some other compiler things which often blur together. Fun fact: the incorrect usage of nme.ScalaObject in Contexts which I reported when first broaching the namespace subject became a compile time error during the writing of this patch, because there is no longer any such thing as nme.ScalaObject. It's a little bit like magic. No review.
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Definitions.scala8
-rw-r--r--src/compiler/scala/tools/nsc/symtab/NameManglers.scala14
-rw-r--r--src/compiler/scala/tools/nsc/symtab/StdNames.scala120
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala87
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala18
-rw-r--r--src/compiler/scala/tools/nsc/transform/AddInterfaces.scala50
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala16
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala3
-rw-r--r--src/library/scala/Math.scala2
-rwxr-xr-xsrc/library/scala/reflect/generic/StdNames.scala4
-rw-r--r--test/files/neg/t3115.check6
12 files changed, 166 insertions, 164 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
index 789f803965..f756d25895 100644
--- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
@@ -21,16 +21,20 @@ trait Definitions extends reflect.generic.StandardDefinitions {
// symbols related to packages
var emptypackagescope: Scope = null //debug
+ // This is the package _root_. The actual root cannot be referenced at
+ // the source level, but _root_ is essentially a function () => <root>.
lazy val RootPackage: Symbol = {
- val rp=NoSymbol.newValue(NoPosition, nme.ROOTPKG)
+ val rp = NoSymbol.newValue(NoPosition, nme.ROOTPKG)
.setFlag(FINAL | MODULE | PACKAGE | JAVA)
.setInfo(PolyType(List(), RootClass.tpe))
RootClass.sourceModule = rp
rp
}
+ // This is the actual root of everything, including the package _root_.
lazy val RootClass: ModuleClassSymbol = NoSymbol.newModuleClass(NoPosition, tpnme.ROOT)
.setFlag(FINAL | MODULE | PACKAGE | JAVA).setInfo(rootLoader)
+ // The empty package, which holds all top level types without given packages.
lazy val EmptyPackage = RootClass.newPackage(NoPosition, nme.EMPTY_PACKAGE_NAME).setFlag(FINAL)
lazy val EmptyPackageClass = EmptyPackage.moduleClass
@@ -142,7 +146,6 @@ trait Definitions extends reflect.generic.StandardDefinitions {
lazy val ScalaObjectClass = getClass("scala.ScalaObject")
lazy val PartialFunctionClass = getClass("scala.PartialFunction")
lazy val SymbolClass = getClass("scala.Symbol")
- lazy val Symbol_apply = getMember(SymbolClass.companionModule, nme.apply)
lazy val StringClass = getClass(sn.String)
lazy val ClassClass = getClass(sn.Class)
def Class_getMethod = getMember(ClassClass, nme.getMethod_)
@@ -157,6 +160,7 @@ trait Definitions extends reflect.generic.StandardDefinitions {
lazy val ConsoleModule: Symbol = getModule("scala.Console")
lazy val ScalaRunTimeModule: Symbol = getModule("scala.runtime.ScalaRunTime")
lazy val SymbolModule: Symbol = getModule("scala.Symbol")
+ lazy val Symbol_apply = getMember(SymbolModule, nme.apply)
def SeqFactory = getMember(ScalaRunTimeModule, nme.Seq)
def arrayApplyMethod = getMember(ScalaRunTimeModule, "array_apply")
def arrayUpdateMethod = getMember(ScalaRunTimeModule, "array_update")
diff --git a/src/compiler/scala/tools/nsc/symtab/NameManglers.scala b/src/compiler/scala/tools/nsc/symtab/NameManglers.scala
index d9a1da7731..37f65fd348 100644
--- a/src/compiler/scala/tools/nsc/symtab/NameManglers.scala
+++ b/src/compiler/scala/tools/nsc/symtab/NameManglers.scala
@@ -98,16 +98,16 @@ trait NameManglers {
newTermName(prefix + DEFAULT_GETTER_STRING + pos)
}
- def implClassName(name: Name): Name = name.toTypeName append IMPL_CLASS_SUFFIX
- def interfaceName(implname: Name): Name = implname stripEnd IMPL_CLASS_SUFFIX
- def localDummyName(clazz: Symbol): Name = newTermName(LOCALDUMMY_PREFIX + clazz.name + ">")
- def productAccessorName(i: Int): Name = newTermName("_" + i)
- def superName(name: Name): Name = newTermName(SUPER_PREFIX_STRING + name)
+ def implClassName(name: Name): TypeName = name append IMPL_CLASS_SUFFIX toTypeName
+ def interfaceName(implname: Name): TypeName = implname stripEnd IMPL_CLASS_SUFFIX toTypeName
+ def localDummyName(clazz: Symbol): TermName = newTermName(LOCALDUMMY_PREFIX + clazz.name + ">")
+ def productAccessorName(i: Int): TermName = newTermName("_" + i)
+ def superName(name: Name): TermName = newTermName(SUPER_PREFIX_STRING + name)
/** The name of an accessor for protected symbols. */
- def protName(name: Name): Name = newTermName(PROTECTED_PREFIX + name)
+ def protName(name: Name): TermName = newTermName(PROTECTED_PREFIX + name)
/** The name of a setter for protected symbols. Used for inherited Java fields. */
- def protSetterName(name: Name): Name = newTermName(PROTECTED_SET_PREFIX + name)
+ def protSetterName(name: Name): TermName = newTermName(PROTECTED_SET_PREFIX + name)
}
}
diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
index 54c3ff9310..49009ece39 100644
--- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala
+++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
@@ -12,37 +12,70 @@ trait StdNames extends reflect.generic.StdNames with NameManglers {
self: SymbolTable =>
trait CompilerCommonNames extends LibraryCommonNames {
+ // value types are all used as terms as well
+ final val Boolean: NameType = "Boolean"
+ final val Byte: NameType = "Byte"
+ final val Char: NameType = "Char"
+ final val Double: NameType = "Double"
+ final val Float: NameType = "Float"
+ final val Int: NameType = "Int"
+ final val Long: NameType = "Long"
+ final val Short: NameType = "Short"
+ final val Unit: NameType = "Unit"
+
+ // types whose companions we utilize
+ final val Array: NameType = "Array"
+ final val List: NameType = "List"
+ final val Seq: NameType = "Seq"
+ final val Symbol: NameType = "Symbol"
+
+ // fictions we use as both types and terms
+ final val ERROR: NameType = "<error>"
+ final val NO_NAME: NameType = "<none>" // formerly NOSYMBOL
+ final val WILDCARD: NameType = "_"
+ }
+
+ trait CompilerTypeNames extends CompilerCommonNames {
+ final val BYNAME_PARAM_CLASS_NAME: NameType = "<byname>"
+ final val EQUALS_PATTERN_NAME: NameType = "<equals>"
+ final val JAVA_REPEATED_PARAM_CLASS_NAME: NameType = "<repeated...>"
+ final val LOCAL_CHILD: NameType = "<local child>"
+ final val REPEATED_PARAM_CLASS_NAME: NameType = "<repeated>"
+ final val WILDCARD_STAR: NameType = "_*"
+
final val Any: NameType = "Any"
final val AnyRef: NameType = "AnyRef"
final val AnyVal: NameType = "AnyVal"
- final val Array: NameType = "Array"
- final val Boolean: NameType = "Boolean"
- final val Byte: NameType = "Byte"
- final val Char: NameType = "Char"
- final val Double: NameType = "Double"
- final val Float: NameType = "Float"
- final val Function: NameType = "Function"
- final val Int: NameType = "Int"
- final val List: NameType = "List"
- final val Long: NameType = "Long"
- final val Nil: NameType = "Nil"
+ final val Nothing: NameType = "Nothing"
+ final val Null: NameType = "Null"
final val Object: NameType = "Object"
final val PartialFunction: NameType = "PartialFunction"
- final val Predef: NameType = "Predef"
final val Product: NameType = "Product"
final val ScalaObject: NameType = "ScalaObject"
- final val ScalaRunTime: NameType = "ScalaRunTime"
- final val Seq: NameType = "Seq"
- final val Short: NameType = "Short"
- final val Some: NameType = "Some"
+ final val Serializable: NameType = "Serializable"
+ final val Singleton: NameType = "Singleton"
final val String: NameType = "String"
- final val Symbol: NameType = "Symbol"
- final val Unit: NameType = "Unit"
+ final val Throwable: NameType = "Throwable"
- final val ERROR: NameType = "<error>"
- final val NO_NAME: NameType = "<none>" // formerly NOSYMBOL
- final val STAR: NameType = "*"
- final val WILDCARD: NameType = "_"
+ // Annotation types
+ final val AnnotationDefaultATTR: NameType = "AnnotationDefault"
+ final val BridgeATTR: NameType = "Bridge"
+ final val ClassfileAnnotationATTR: NameType = "RuntimeInvisibleAnnotations" // RetentionPolicy.CLASS. Currently not used (Apr 2009).
+ final val CodeATTR: NameType = "Code"
+ final val ConstantValueATTR: NameType = "ConstantValue"
+ final val DeprecatedATTR: NameType = "Deprecated"
+ final val ExceptionsATTR: NameType = "Exceptions"
+ final val InnerClassesATTR: NameType = "InnerClasses"
+ final val JacoMetaATTR: NameType = "JacoMeta"
+ final val LineNumberTableATTR: NameType = "LineNumberTable"
+ final val LocalVariableTableATTR: NameType = "LocalVariableTable"
+ final val RuntimeAnnotationATTR: NameType = "RuntimeVisibleAnnotations" // RetentionPolicy.RUNTIME
+ final val RuntimeParamAnnotationATTR: NameType = "RuntimeVisibleParameterAnnotations" // RetentionPolicy.RUNTIME (annotations on parameters)
+ final val ScalaATTR: NameType = "Scala"
+ final val ScalaSignatureATTR: NameType = "ScalaSig"
+ final val SignatureATTR: NameType = "Signature"
+ final val SourceFileATTR: NameType = "SourceFile"
+ final val SyntheticATTR: NameType = "Synthetic"
}
trait CompilerTermNames extends CompilerCommonNames {
@@ -110,8 +143,14 @@ trait StdNames extends reflect.generic.StdNames with NameManglers {
val OUTER_LOCAL: NameType = "$outer " // note the space
val SELF: NameType = "$this"
val SPECIALIZED_INSTANCE: NameType = "specInstance$"
+ val STAR: NameType = "*"
val THIS: NameType = "_$this"
+ final val Nil: NameType = "Nil"
+ final val Predef: NameType = "Predef"
+ final val ScalaRunTime: NameType = "ScalaRunTime"
+ final val Some: NameType = "Some"
+
// Compiler utilized names
// val productElementName: NameType = "productElementName"
val TYPE_ : NameType = "TYPE"
@@ -226,43 +265,6 @@ trait StdNames extends reflect.generic.StdNames with NameManglers {
val toDouble: NameType = "toDouble"
}
- trait CompilerTypeNames extends CompilerCommonNames {
- final val BYNAME_PARAM_CLASS_NAME: NameType = "<byname>"
- final val EQUALS_PATTERN_NAME: NameType = "<equals>"
- final val JAVA_REPEATED_PARAM_CLASS_NAME: NameType = "<repeated...>"
- final val LOCAL_CHILD: NameType = "<local child>"
- final val REPEATED_PARAM_CLASS_NAME: NameType = "<repeated>"
- final val WILDCARD_STAR: NameType = "_*"
-
- final val Nothing: NameType = "Nothing"
- final val Null: NameType = "Null"
- final val Serializable: NameType = "Serializable"
- final val Singleton: NameType = "Singleton"
- final val Throwable: NameType = "Throwable"
-
- // Stores Java annotations on parameters with RetentionPolicy.RUNTIME
- // Stores Java annotations with RetentionPolicy.CLASS. Currently not used (Apr 2009).
- // Stores Java annotations with RetentionPolicy.RUNTIME
- final val AnnotationDefaultATTR: NameType = "AnnotationDefault"
- final val BridgeATTR: NameType = "Bridge"
- final val ClassfileAnnotationATTR: NameType = "RuntimeInvisibleAnnotations"
- final val CodeATTR: NameType = "Code"
- final val ConstantValueATTR: NameType = "ConstantValue"
- final val DeprecatedATTR: NameType = "Deprecated"
- final val ExceptionsATTR: NameType = "Exceptions"
- final val InnerClassesATTR: NameType = "InnerClasses"
- final val JacoMetaATTR: NameType = "JacoMeta"
- final val LineNumberTableATTR: NameType = "LineNumberTable"
- final val LocalVariableTableATTR: NameType = "LocalVariableTable"
- final val RuntimeAnnotationATTR: NameType = "RuntimeVisibleAnnotations"
- final val RuntimeParamAnnotationATTR: NameType = "RuntimeVisibleParameterAnnotations"
- final val ScalaATTR: NameType = "Scala"
- final val ScalaSignatureATTR: NameType = "ScalaSig"
- final val SignatureATTR: NameType = "Signature"
- final val SourceFileATTR: NameType = "SourceFile"
- final val SyntheticATTR: NameType = "Synthetic"
- }
-
object tpnme extends CompilerTypeNames with LibraryTypeNames {
type NameType = TypeName
implicit def createNameType(name: String): TypeName = newTypeName(name)
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index e15328c6a1..ba83f173aa 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -372,17 +372,29 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
final def isAnonymousClass = isClass && (name containsName tpnme.ANON_CLASS_NAME)
final def isAnonymousFunction = isSynthetic && (name containsName tpnme.ANON_FUN_NAME)
+ final def isAnonOrRefinementClass = isAnonymousClass || isRefinementClass
- final def isClassOfModule = isModuleClass || isClass && nme.isLocalName(name)
final def isPackageObject = isModule && name == nme.PACKAGEkw && owner.isPackageClass
final def isPackageObjectClass = isModuleClass && name.toTermName == nme.PACKAGEkw && owner.isPackageClass
final def definedInPackage = owner.isPackageClass || owner.isPackageObjectClass
- final def isPredefModule = this == PredefModule // not printed as a prefix
final def isJavaInterface = isJavaDefined && isTrait
// not printed as prefixes
+ final def isRootOrEmpty = (this == EmptyPackageClass) || (this == RootClass)
+ final def isPredefModule = this == PredefModule
final def isScalaPackage = (this == ScalaPackage) || (isPackageObject && owner == ScalaPackageClass)
- final def isScalaPackageClass = (this == ScalaPackageClass) || (isPackageObjectClass && owner == ScalaPackageClass)
+ final def isScalaPackageClass = skipPackageObject == ScalaPackageClass
+
+ /** If this is a package object or package object class, its owner: otherwise this.
+ */
+ final def skipPackageObject: Symbol = if (isPackageObjectClass) owner else this
+
+ /** Conditions where we omit the prefix when printing a symbol, to avoid
+ * unpleasantries like Predef.String, $iw.$iw.Foo and <empty>.Bippy.
+ */
+ final def printWithoutPrefix = !settings.debug.value && (
+ isScalaPackageClass || isPredefModule || isRootOrEmpty || isAnonOrRefinementClass || isInterpreterWrapper
+ )
/** Is symbol a monomorphic type?
* assumption: if a type starts out as monomorphic, it will not acquire
@@ -415,8 +427,8 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
final def isInterpreterWrapper =
(isModule || isModuleClass) &&
owner.isEmptyPackageClass &&
- name.toString.startsWith(nme.INTERPRETER_LINE_PREFIX) &&
- name.toString.endsWith(nme.INTERPRETER_WRAPPER_SUFFIX)
+ (name startsWith nme.INTERPRETER_LINE_PREFIX) &&
+ (name endsWith nme.INTERPRETER_WRAPPER_SUFFIX)
override def isEffectiveRoot = super.isEffectiveRoot || isInterpreterWrapper
@@ -462,7 +474,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
/** Is this symbol a trait which needs an implementation class? */
final def needsImplClass: Boolean =
- isTrait && (!hasFlag(INTERFACE) || hasFlag(lateINTERFACE)) && !isImplClass
+ isTrait && (!isInterface || hasFlag(lateINTERFACE)) && !isImplClass
/** Is this a symbol which exists only in the implementation class, not in its trait? */
final def isImplOnly: Boolean =
@@ -520,7 +532,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
* - it is defined within a local class
*/
final def isLocalClass: Boolean =
- isClass && (isAnonymousClass || isRefinementClass || isLocal ||
+ isClass && (isAnonOrRefinementClass || isLocal ||
!owner.isPackageClass && owner.isLocalClass)
/* code for fixing nested objects
@@ -1219,10 +1231,11 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
res
}
- /** @PP: Added diagram because every time I come through here I end up
- * losing my train of thought. [Renaming occurs.] This diagram is a
- * bit less necessary since the renaming, but leaving in place
- * due to high artistic merit.
+ /** The internal representation of classes and objects:
+ *
+ * class Foo is "the class" or sometimes "the plain class"
+ * object Foo is "the module"
+ * class Foo$ is "the module class" (invisible to the user: it implements object Foo)
*
* class Foo <
* ^ ^ (2) \
@@ -1239,10 +1252,11 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
* (5) companionSymbol
*/
- /** The class with the same name in the same package as this module or
- * case class factory.
- * Note: does not work for classes owned by methods, see
- * Namers.companionClassOf
+ /** For a module or case factory: the class with the same name in the same package.
+ * For all others: NoSymbol
+ * Note: does not work for classes owned by methods, see Namers.companionClassOf
+ *
+ * object Foo . companionClass --> class Foo
*/
final def companionClass: Symbol = {
if (this != NoSymbol)
@@ -1260,32 +1274,31 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
sym => (sym hasFlag f) && (sym isCoDefinedWith this))
}
- /** The module or case class factory with the same name in the same
- * package as this class.
- * Note: does not work for modules owned by methods, see
- * Namers.companionModuleOf
+ /** For a class: the module or case class factory wiht the same name in the same package.
+ * For all others: NoSymbol
+ * Note: does not work for modules owned by methods, see Namers.companionModuleOf
+ *
+ * class Foo . companionModule --> object Foo
*/
final def companionModule: Symbol =
- if (this.isClass && !this.isAnonymousClass && !this.isRefinementClass)
- companionModule0
+ if (isClass && !isAnonOrRefinementClass) companionModule0
else NoSymbol
- /** For a module its linked class, for a class its linked module or case
- * factory otherwise.
- * Note: does not work for modules owned by methods, see
- * Namers.companionSymbolOf
+ /** For a module: its linked class
+ * For a plain class: its linked module or case factory.
+ * Note: does not work for modules owned by methods, see Namers.companionSymbolOf
+ *
+ * class Foo <-- companionSymbol --> object Foo
*/
final def companionSymbol: Symbol =
if (isTerm) companionClass
- else if (isClass)
- companionModule0
+ else if (isClass) companionModule0
else NoSymbol
/** For a module class: its linked class
* For a plain class: the module class of its linked module.
*
- * Then object Foo has a `moduleClass' (invisible to the user, the backend calls it Foo$
- * linkedClassOfClass goes from class Foo$ to class Foo, and back.
+ * class Foo <-- linkedClassOfClass --> class Foo$
*/
final def linkedClassOfClass: Symbol =
if (isModuleClass) companionClass else companionModule.moduleClass
@@ -1561,21 +1574,11 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
compose(List(kindString,
if (isClassConstructor) owner.simpleName.decode+idString else nameString))
- /** If owner is a package object, its owner, else the normal owner.
- */
- def ownerSkipPackageObject =
- if (owner.isPackageObjectClass) owner.owner else owner
-
/** String representation of location. */
def locationString: String = {
- val owner = ownerSkipPackageObject
- if (owner.isClass &&
- ((!owner.isAnonymousClass &&
- !owner.isRefinementClass &&
- !owner.isInterpreterWrapper &&
- !owner.isRoot &&
- !owner.isEmptyPackageClass) || settings.debug.value))
- " in " + owner else ""
+ val owns = owner.skipPackageObject
+ if (!owns.isClass || (owns.printWithoutPrefix && owns != ScalaPackageClass)) ""
+ else " in " + owns
}
/** String representation of symbol's definition following its name */
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index 6f9b92b60f..b82380c0c2 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -1127,8 +1127,8 @@ trait Types extends reflect.generic.Types { self: SymbolTable =>
override def isHigherKinded = sym.isRefinementClass && underlying.isHigherKinded
override def prefixString =
if (settings.debug.value) sym.nameString + ".this."
- else if (sym.isRoot || sym.isEmptyPackageClass || sym.isInterpreterWrapper || sym.isScalaPackageClass) ""
- else if (sym.isAnonymousClass || sym.isRefinementClass) "this."
+ else if (sym.isAnonOrRefinementClass) "this."
+ else if (sym.printWithoutPrefix) ""
else if (sym.isModuleClass) sym.fullName + "."
else sym.nameString + ".this."
override def safeToString: String =
@@ -1211,10 +1211,7 @@ trait Types extends reflect.generic.Types { self: SymbolTable =>
override def typeSymbol = thistpe.typeSymbol
override def underlying = supertpe
override def prefix: Type = supertpe.prefix
- override def prefixString =
- if (thistpe.prefixString.endsWith("this."))
- thistpe.prefixString.substring(0, thistpe.prefixString.length() - 5) + "super."
- else thistpe.prefixString;
+ override def prefixString = thistpe.prefixString.replaceAll("""this\.$""", "super.")
override def narrow: Type = thistpe.narrow
override def kind = "SuperType"
}
@@ -1367,7 +1364,7 @@ trait Types extends reflect.generic.Types { self: SymbolTable =>
override def isNotNull: Boolean = parents exists (_.isNotNull)
override def isStructuralRefinement: Boolean =
- (typeSymbol.isRefinementClass || typeSymbol.isAnonymousClass) &&
+ typeSymbol.isAnonOrRefinementClass &&
(decls.toList exists { entry => !entry.isConstructor && entry.allOverriddenSymbols.isEmpty })
// override def isNullable: Boolean =
@@ -1952,13 +1949,12 @@ A type's typeSymbol should never be inspected directly.
override def prefixString =
if (settings.debug.value)
super.prefixString
- else if (sym.isRoot || sym.isEmptyPackageClass || sym.isInterpreterWrapper ||
- sym.isAnonymousClass || sym.isRefinementClass || sym.isScalaPackageClass)
+ else if (sym.printWithoutPrefix)
""
else if (sym.isPackageClass)
sym.fullName + "."
- else if (isStable && (sym.name.toString endsWith ".type"))
- sym.name.toString.substring(0, sym.name.length - 4)
+ else if (isStable && (sym.name endsWith ".type"))
+ sym.name.toString dropRight 4
else
super.prefixString
diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
index e3a90fadd3..c26f5295e0 100644
--- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
+++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
@@ -71,33 +71,31 @@ abstract class AddInterfaces extends InfoTransform {
def implClassPhase = currentRun.erasurePhase.next
/** Return the implementation class of a trait; create a new one of one does not yet exist */
- def implClass(iface: Symbol): Symbol = implClassMap.get(iface) match {
- case Some(c) => c
- case None =>
- atPhase(implClassPhase) {
- val implName = nme.implClassName(iface.name)
- var impl = if (iface.owner.isClass) iface.owner.info.decl(implName) else NoSymbol
- if (impl != NoSymbol && settings.XO.value) {
- log("unlinking impl class " + impl)
- iface.owner.info.decls.unlink(impl)
- impl = NoSymbol
- }
- if (impl == NoSymbol) {
- impl = iface.cloneSymbolImpl(iface.owner)
- impl.name = implName
- impl.sourceFile = iface.sourceFile
- if (iface.owner.isClass)
- iface.owner.info.decls enter impl
- }
- if (currentRun.compiles(iface)) currentRun.symSource(impl) = iface.sourceFile
- impl setPos iface.pos
- impl.flags = iface.flags & ~(INTERFACE | lateINTERFACE) | IMPLCLASS
- impl setInfo new LazyImplClassType(iface)
- implClassMap(iface) = impl
- if (settings.debug.value) log("generating impl class " + impl + " in " + iface.owner)//debug
- impl
+ def implClass(iface: Symbol): Symbol = implClassMap.getOrElse(iface, {
+ atPhase(implClassPhase) {
+ val implName = nme.implClassName(iface.name)
+ var impl = if (iface.owner.isClass) iface.owner.info.decl(implName) else NoSymbol
+ if (impl != NoSymbol && settings.XO.value) {
+ log("unlinking impl class " + impl)
+ iface.owner.info.decls.unlink(impl)
+ impl = NoSymbol
}
- }
+ if (impl == NoSymbol) {
+ impl = iface.cloneSymbolImpl(iface.owner)
+ impl.name = implName
+ impl.sourceFile = iface.sourceFile
+ if (iface.owner.isClass)
+ iface.owner.info.decls enter impl
+ }
+ if (currentRun.compiles(iface)) currentRun.symSource(impl) = iface.sourceFile
+ impl setPos iface.pos
+ impl.flags = iface.flags & ~(INTERFACE | lateINTERFACE) | IMPLCLASS
+ impl setInfo new LazyImplClassType(iface)
+ implClassMap(iface) = impl
+ if (settings.debug.value) log("generating impl class " + impl + " in " + iface.owner)//debug
+ impl
+ }
+ })
/** <p>
* A lazy type to set the info of an implementation class
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index f5033dc58c..eb96a6fba6 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -48,7 +48,7 @@ trait Contexts { self: Analyzer =>
assert(ScalaPackage ne null, "Scala package is null")
imps += ScalaPackage
if (!(treeInfo.isUnitInScala(unit.body, nme.Predef) ||
- treeInfo.isUnitInScala(unit.body, nme.ScalaObject) ||
+ treeInfo.isUnitInScala(unit.body, tpnme.ScalaObject) ||
treeInfo.containsLeadingPredefImport(List(unit.body))))
imps += PredefModule
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
index ebcd3c3777..22a60a8abf 100644
--- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
@@ -234,18 +234,16 @@ trait TypeDiagnostics {
// functions to manipulate the name
def preQualify() = modifyName(trueOwner.fullName + "." + _)
def postQualify() = modifyName(_ + "(in " + trueOwner + ")")
- def scalaQualify() = if (isInScalaOrPredef) preQualify()
+ def scalaQualify() = if (inPredefOrScala) preQualify()
def typeQualify() = if (sym.isTypeParameterOrSkolem) postQualify()
def nameQualify() = if (trueOwner.isPackageClass) preQualify() else postQualify()
- def trueOwner = tp.typeSymbol.ownerSkipPackageObject
- def aliasOwner = tp.typeSymbolDirect.ownerSkipPackageObject
+ def trueOwner = tp.typeSymbol.owner.skipPackageObject
+ def aliasOwner = tp.typeSymbolDirect.owner.skipPackageObject
def owners = List(trueOwner, aliasOwner)
- def isInScalaOrPredef = owners exists {
- case ScalaPackageClass | PredefModuleClass => true
- case _ => false
- }
+ private def scalaAndPredef = Set(ScalaPackageClass, PredefModuleClass)
+ def inPredefOrScala = owners exists scalaAndPredef
def sym_==(other: TypeDiag) = tp.typeSymbol == other.tp.typeSymbol
def owner_==(other: TypeDiag) = trueOwner == other.trueOwner
@@ -264,9 +262,9 @@ trait TypeDiagnostics {
|tp.typeSymbol.owner = %s
|tp.typeSymbolDirect = %s
|tp.typeSymbolDirect.owner = %s
- |isInScalaOrPredef = %s
+ |inPredefOrScala = %s
""".stripMargin.format(
- tp, tp.typeSymbol, tp.typeSymbol.owner, tp.typeSymbolDirect, tp.typeSymbolDirect.owner, isInScalaOrPredef
+ tp, tp.typeSymbol, tp.typeSymbol.owner, tp.typeSymbolDirect, tp.typeSymbolDirect.owner, inPredefOrScala
)
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 752931388d..65ce41c020 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1780,8 +1780,7 @@ trait Typers { self: Analyzer =>
if (!meth.isPrimaryConstructor &&
(!meth.owner.isClass ||
meth.owner.isModuleClass ||
- meth.owner.isAnonymousClass ||
- meth.owner.isRefinementClass))
+ meth.owner.isAnonOrRefinementClass))
error(ddef.pos, "constructor definition not allowed here")
typed(ddef.rhs)
} else {
diff --git a/src/library/scala/Math.scala b/src/library/scala/Math.scala
index 69a3985871..a4189fea8a 100644
--- a/src/library/scala/Math.scala
+++ b/src/library/scala/Math.scala
@@ -13,7 +13,7 @@ package scala
* operations such as the elementary exponential, logarithm, square root, and
* trigonometric functions.
*/
-@deprecated("use scala.math package instead")
+@deprecated("use scala.math package object instead.\n(Example package object usage: scala.math.Pi )")
object Math extends MathCommon {
@deprecated("Use scala.Byte.MinValue instead")
val MIN_BYTE = java.lang.Byte.MIN_VALUE
diff --git a/src/library/scala/reflect/generic/StdNames.scala b/src/library/scala/reflect/generic/StdNames.scala
index f0fb790a5e..70e24e4dc5 100755
--- a/src/library/scala/reflect/generic/StdNames.scala
+++ b/src/library/scala/reflect/generic/StdNames.scala
@@ -29,12 +29,12 @@ trait StdNames extends LowPriorityStdNames {
val IMPORT: NameType = "<import>"
val MODULE_SUFFIX: NameType = "$module"
val ROOT: NameType = "<root>"
- val ROOTPKG: NameType = "_root_"
}
trait LibraryTermNames extends LibraryCommonNames {
val EXPAND_SEPARATOR_STRING = "$$"
- val LOCAL_SUFFIX_STRING = " "
+ val LOCAL_SUFFIX_STRING = " "
+ val ROOTPKG: NameType = "_root_"
/** The expanded name of `name' relative to this class `base` with given `separator`
*/
diff --git a/test/files/neg/t3115.check b/test/files/neg/t3115.check
index 04f64eec3f..b9c0ed9829 100644
--- a/test/files/neg/t3115.check
+++ b/test/files/neg/t3115.check
@@ -1,10 +1,12 @@
t3115.scala:6: error: object Math in object sc is deprecated:
println(sc.Math)
^
-t3115.scala:7: error: object Math in package scala is deprecated: use scala.math package instead
+t3115.scala:7: error: object Math in package scala is deprecated: use scala.math package object instead.
+(Example package object usage: scala.math.Pi )
println(scala.Math)
^
-t3115.scala:8: error: object Math in package scala is deprecated: use scala.math package instead
+t3115.scala:8: error: object Math in package scala is deprecated: use scala.math package object instead.
+(Example package object usage: scala.math.Pi )
scala.Math.Pi
^
three errors found