aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-03-22 11:22:50 +0100
committerMartin Odersky <odersky@gmail.com>2017-04-11 09:33:10 +0200
commitccba1b7762cc54c01ad8e5f949b8c6b1674122e0 (patch)
tree80df0c0950623fd68ce0e6489cf6d2456d56cdc8
parent67105e3f36378d652aa919e23aa3b2678004bdc6 (diff)
downloaddotty-ccba1b7762cc54c01ad8e5f949b8c6b1674122e0.tar.gz
dotty-ccba1b7762cc54c01ad8e5f949b8c6b1674122e0.tar.bz2
dotty-ccba1b7762cc54c01ad8e5f949b8c6b1674122e0.zip
Self-checked structured qualified names
This is a temporary step. If semanticNames is true we construct structured qualified names, but check they have the same string representation as the unstructured names.
-rw-r--r--compiler/src/dotty/tools/dotc/core/SymDenotations.scala31
1 files changed, 27 insertions, 4 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
index 6d1a006ed..150bb1584 100644
--- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -392,7 +392,7 @@ object SymDenotations {
* A separator "" means "flat name"; the real separator in this case is "$" and
* enclosing packages do not form part of the name.
*/
- def fullNameSeparated(separator: String)(implicit ctx: Context): Name = {
+ def fullNameSeparated(separator: String, semantic: Boolean)(implicit ctx: Context): Name = {
var sep = separator
var stopAtPackage = false
if (sep.isEmpty) {
@@ -409,12 +409,34 @@ object SymDenotations {
encl = encl.owner
sep += "~"
}
- if (owner.is(ModuleClass, butNot = Package) && sep == "$") sep = "" // duplicate scalac's behavior: don't write a double '$$' for module class members.
- val fn = encl.fullNameSeparated(separator) ++ sep ++ name
+ var prefix = encl.fullNameSeparated(separator, semantic)
+ val fn =
+ if (semantic) {
+ if (sep == "$")
+ // duplicate scalac's behavior: don't write a double '$$' for module class members.
+ prefix = prefix.without(NameInfo.ModuleClassKind)
+ prefix.derived(NameInfo.Qualified(name.toTermName, sep))
+ }
+ else {
+ if (owner.is(ModuleClass, butNot = Package) && sep == "$")
+ // duplicate scalac's behavior: don't write a double '$$' for module class members.
+ sep = ""
+ prefix ++ sep ++ name
+ }
if (isType) fn.toTypeName else fn.toTermName
}
}
+ def fullNameSeparated(separator: String)(implicit ctx: Context): Name =
+ if (Config.semanticNames) {
+ val fn1 = fullNameSeparated(separator, false)
+ val fn2 = fullNameSeparated(separator, true)
+ assert(fn1.toString == fn2.toString, s"mismatch, was: $fn1, sem: $fn2")
+ fn2
+ }
+ else fullNameSeparated(separator, false)
+ }
+
/** The encoded flat name of this denotation, where joined names are separated by `separator` characters. */
def flatName(implicit ctx: Context): Name = fullNameSeparated("")
@@ -1220,7 +1242,8 @@ object SymDenotations {
// ----- denotation fields and accessors ------------------------------
- if (initFlags is (Module, butNot = Package)) assert(name.isModuleClassName, s"module naming inconsistency: $name")
+ if (initFlags is (Module, butNot = Package))
+ assert(name.isModuleClassName, s"module naming inconsistency: ${name.debugString}")
/** The symbol asserted to have type ClassSymbol */
def classSymbol: ClassSymbol = symbol.asInstanceOf[ClassSymbol]