Skip to content

Commit 6b575ab

Browse files
committed
Introduce mangled method
Mangled is like toSimpleName, except that it keeps the term/type distinction.
1 parent 62c11a7 commit 6b575ab

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

compiler/src/dotty/tools/dotc/core/Names.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ object Names {
6666
def isSimple: Boolean
6767
def asSimpleName: SimpleTermName
6868
def toSimpleName: SimpleTermName
69+
def mangled: Name
70+
6971
def rewrite(f: PartialFunction[Name, Name]): ThisName
7072
def collect[T](f: PartialFunction[Name, T]): Option[T]
7173
def mapLast(f: SimpleTermName => SimpleTermName): ThisName
@@ -263,6 +265,8 @@ object Names {
263265
def isSimple = true
264266
def asSimpleName = this
265267
def toSimpleName = this
268+
def mangled = this
269+
266270
def rewrite(f: PartialFunction[Name, Name]): ThisName =
267271
if (f.isDefinedAt(this)) likeSpaced(f(this)) else this
268272
def collect[T](f: PartialFunction[Name, T]): Option[T] = f.lift(this)
@@ -306,6 +310,8 @@ object Names {
306310
def isSimple = toTermName.isSimple
307311
def asSimpleName = toTermName.asSimpleName
308312
def toSimpleName = toTermName.toSimpleName
313+
def mangled = toTermName.toSimpleName.toTypeName
314+
309315
def rewrite(f: PartialFunction[Name, Name]): ThisName = toTermName.rewrite(f).toTypeName
310316
def collect[T](f: PartialFunction[Name, T]): Option[T] = toTermName.collect(f)
311317
def mapLast(f: SimpleTermName => SimpleTermName) = toTermName.mapLast(f).toTypeName
@@ -345,6 +351,7 @@ object Names {
345351
if (simpleName == null) simpleName = termName(toString)
346352
simpleName
347353
}
354+
def mangled = toSimpleName
348355

349356
def rewrite(f: PartialFunction[Name, Name]): ThisName =
350357
if (f.isDefinedAt(this)) likeSpaced(f(this))

compiler/src/dotty/tools/dotc/core/Scopes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,10 @@ object Scopes {
396396

397397
class PackageScope extends MutableScope {
398398
override final def newScopeEntry(name: Name, sym: Symbol)(implicit ctx: Context): ScopeEntry =
399-
super.newScopeEntry(name.toSimpleName, sym)
399+
super.newScopeEntry(name.mangled, sym)
400400

401401
override final def lookupEntry(name: Name)(implicit ctx: Context): ScopeEntry =
402-
super.lookupEntry(name.toSimpleName)
402+
super.lookupEntry(name.mangled)
403403
}
404404

405405
/** Create a new scope */

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
421421
val tag = readByte()
422422
val end = readEnd()
423423
var name: Name = readName()
424-
val sname = name.toSimpleName
424+
val mname = name.mangled
425425
if (tag == TYPEDEF || tag == TYPEPARAM) name = name.toTypeName
426426
skipParams()
427427
val ttag = nextUnsharedTag
@@ -438,7 +438,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
438438
def adjustIfModule(completer: LazyType) =
439439
if (flags is Module) ctx.adjustModuleCompleter(completer, name) else completer
440440
val sym =
441-
roots.find(root => (root.owner eq ctx.owner) && root.name.toSimpleName == sname && root.isType == name.isTypeName) match {
441+
roots.find(root => (root.owner eq ctx.owner) && root.name.mangled == mname) match {
442442
case Some(rootd) =>
443443
pickling.println(i"overwriting ${rootd.symbol} # ${rootd.hashCode}")
444444
rootd.name = name

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
446446
flags = flags &~ Scala2SuperAccessor
447447
}
448448

449-
val sname = name.toSimpleName
450-
def nameMatches(rootName: Name) = sname == rootName.toSimpleName
449+
val mname = name.mangled
450+
def nameMatches(rootName: Name) = mname == rootName.mangled
451451
def isClassRoot = nameMatches(classRoot.name) && (owner == classRoot.owner) && !(flags is ModuleClass)
452452
def isModuleClassRoot = nameMatches(moduleClassRoot.name) && (owner == moduleClassRoot.owner) && (flags is Module)
453453
def isModuleRoot = nameMatches(moduleClassRoot.name.sourceModuleName) && (owner == moduleClassRoot.owner) && (flags is Module)

0 commit comments

Comments
 (0)