Skip to content

Commit cabf8ed

Browse files
committed
Properly integrate TraitSetter names
1 parent 2cdf186 commit cabf8ed

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ object NameInfo {
1919
type Kind = Int
2020

2121
val TermNameKind = 0
22-
val QualifiedKind = 1
23-
val DefaultGetterKind = 3
24-
val VariantKind = 4
25-
val SuperAccessorKind = 5
26-
val InitializerKind = 6
22+
val SelectKind = 1
23+
val FlattenKind = 2
24+
val ExpandKind = 3
25+
val TraitSetterKind = 4
26+
val DefaultGetterKind = 5
27+
val VariantKind = 6
28+
val SuperAccessorKind = 7
29+
val InitializerKind = 8
2730
val ModuleClassKind = 10
2831

2932
val qualifier: Map[String, SimpleTermName => Qualified] =
@@ -32,7 +35,7 @@ object NameInfo {
3235
str.EXPAND_SEPARATOR -> Expand,
3336
str.TRAIT_SETTER_SEPARATOR -> TraitSetter)
3437

35-
def definesNewName(kind: Kind) = kind <= QualifiedKind
38+
def definesNewName(kind: Kind) = kind <= TraitSetterKind
3639

3740
/** TermNames have the lowest possible kind */
3841
val TermName = new NameInfo {
@@ -41,32 +44,36 @@ object NameInfo {
4144
}
4245

4346
trait Qualified extends NameInfo {
47+
def kind: Kind
4448
def name: SimpleTermName
4549
def separator: String
4650
def newLikeThis(name: SimpleTermName): Qualified // TODO: should use copy instead after bootstrap
4751

48-
def kind = QualifiedKind
4952
override def map(f: SimpleTermName => SimpleTermName): NameInfo = newLikeThis(f(name))
5053
def mkString(underlying: TermName) = s"$underlying$separator$name"
5154
override def toString = s"${getClass.getSimpleName}($name)"
5255
}
5356

5457
case class Select(val name: SimpleTermName) extends Qualified {
58+
def kind = SelectKind
5559
def separator = "."
5660
def newLikeThis(name: SimpleTermName) = Select(name)
5761
}
5862

5963
case class Flatten(val name: SimpleTermName) extends Qualified {
64+
def kind = FlattenKind
6065
def separator = "$"
6166
def newLikeThis(name: SimpleTermName) = Flatten(name)
6267
}
6368

6469
case class Expand(val name: SimpleTermName) extends Qualified {
70+
def kind = ExpandKind
6571
def separator = str.EXPAND_SEPARATOR
6672
def newLikeThis(name: SimpleTermName) = Expand(name)
6773
}
6874

6975
case class TraitSetter(val name: SimpleTermName) extends Qualified {
76+
def kind = TraitSetterKind
7077
def separator = nme.TRAIT_SETTER_SEPARATOR.toString
7178
def newLikeThis(name: SimpleTermName) = TraitSetter(name)
7279
}

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ object NameOps {
8282
def isLoopHeaderLabel = (name startsWith WHILE_PREFIX) || (name startsWith DO_WHILE_PREFIX)
8383
def isProtectedAccessorName = name startsWith PROTECTED_PREFIX
8484
def isReplWrapperName = name.toSimpleName containsSlice INTERPRETER_IMPORT_WRAPPER
85-
def isTraitSetterName = name.toSimpleName containsSlice TRAIT_SETTER_SEPARATOR
85+
def isTraitSetterName =
86+
if (Config.semanticNames) name.is(NameInfo.TraitSetterKind)
87+
else name containsSlice TRAIT_SETTER_SEPARATOR
8688
def isSetterName = name endsWith SETTER_SUFFIX
8789
def isSingletonName = name endsWith SINGLETON_SUFFIX
8890
def isModuleClassName =
@@ -411,10 +413,16 @@ object NameOps {
411413
def fieldName: TermName =
412414
if (name.isSetterName) {
413415
if (name.isTraitSetterName) {
414-
// has form <$-separated-trait-name>$_setter_$ `name`_$eq
415-
val start = name.lastPart.indexOfSlice(TRAIT_SETTER_SEPARATOR) + TRAIT_SETTER_SEPARATOR.length
416-
val end = name.lastPart.indexOfSlice(SETTER_SUFFIX)
417-
name.mapLast(n => (n.slice(start, end) ++ LOCAL_SUFFIX).asSimpleName)
416+
if (Config.semanticNames) {
417+
val DerivedTermName(_, NameInfo.TraitSetter(original)) = name
418+
original ++ LOCAL_SUFFIX
419+
}
420+
else {
421+
// has form <$-separated-trait-name>$_setter_$ `name`_$eq
422+
val start = name.indexOfSlice(TRAIT_SETTER_SEPARATOR) + TRAIT_SETTER_SEPARATOR.length
423+
val end = name.indexOfSlice(SETTER_SUFFIX)
424+
(name.slice(start, end) ++ LOCAL_SUFFIX).asTermName
425+
}
418426
} else getterName.fieldName
419427
}
420428
else name.mapLast(n => (n ++ LOCAL_SUFFIX).asSimpleName)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class TreePickler(pickler: TastyPickler) {
6262
private def pickleName(sym: Symbol)(implicit ctx: Context): Unit = {
6363
val nameRef =
6464
if (Config.semanticNames) {
65-
if (sym is Flags.ExpandedName) assert(sym.name.is(NameInfo.QualifiedKind))
65+
if (sym is Flags.ExpandedName) assert(sym.name.is(NameInfo.ExpandKind))
6666
nameIndex(sym.name)
6767
}
6868
else {

0 commit comments

Comments
 (0)