Skip to content

Commit fcbe1fd

Browse files
committed
Make module var names semantic
1 parent 217bdcd commit fcbe1fd

File tree

5 files changed

+5
-25
lines changed

5 files changed

+5
-25
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ object NameKinds {
250250
val AvoidClashName = new SuffixNameKind(AVOIDCLASH, "$_avoid_name_clash_$")
251251
val DirectName = new SuffixNameKind(DIRECT, "$direct")
252252
val FieldName = new SuffixNameKind(FIELD, "$$local")
253+
val ModuleVarName = new SuffixNameKind(OBJECTVAR, "$module")
253254
val ModuleClassName = new SuffixNameKind(OBJECTCLASS, "$", optInfoString = "ModuleClass")
254255

255256
object SignedName extends NameKind(63) {

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

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,13 @@ object NameOps {
5757

5858
def isConstructorName = name == CONSTRUCTOR || name == TRAIT_CONSTRUCTOR
5959
def isStaticConstructorName = name == STATIC_CONSTRUCTOR
60-
def isImplClassName = name endsWith IMPL_CLASS_SUFFIX
6160
def isLocalDummyName = name startsWith LOCALDUMMY_PREFIX
6261
def isReplWrapperName = name.toSimpleName containsSlice INTERPRETER_IMPORT_WRAPPER
6362
def isSetterName = name endsWith SETTER_SUFFIX
6463
def isImportName = name startsWith IMPORT
6564
def isScala2LocalSuffix = name.endsWith(" ")
66-
def isModuleVarName(name: Name): Boolean =
67-
name.stripAnonNumberSuffix endsWith MODULE_VAR_SUFFIX
68-
def isSelectorName = name.startsWith(" ") && name.tail.forall(_.isDigit)
65+
def isModuleVarName(name: Name): Boolean = name.exclude(UniqueName).is(ModuleVarName)
66+
def isSelectorName = name.startsWith("_") && name.tail.forall(_.isDigit)
6967
def isOuterSelect = name.endsWith(nme.OUTER_SELECT)
7068

7169
/** Is name a variable name? */
@@ -86,21 +84,6 @@ object NameOps {
8684
false
8785
}
8886

89-
/** If the name ends with $nn where nn are
90-
* all digits, strip the $ and the digits.
91-
* Otherwise return the argument.
92-
*/
93-
def stripAnonNumberSuffix: Name = {
94-
var pos = name.length
95-
while (pos > 0 && name(pos - 1).isDigit)
96-
pos -= 1
97-
98-
if (pos > 0 && pos < name.length && name(pos - 1) == '$')
99-
name take (pos - 1)
100-
else
101-
name
102-
}
103-
10487
/** Convert this module name to corresponding module class name */
10588
def moduleClassName: TypeName = name.derived(ModuleClassName).toTypeName
10689

@@ -345,9 +328,6 @@ object NameOps {
345328
def stripScala2LocalSuffix: TermName =
346329
if (name.isScala2LocalSuffix) name.init.asTermName else name
347330

348-
def moduleVarName: TermName =
349-
name ++ MODULE_VAR_SUFFIX
350-
351331
/** The name unary_x for a prefix operator x */
352332
def toUnaryName: TermName = name match {
353333
case raw.MINUS => UNARY_-

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ object StdNames {
117117
val INTERPRETER_WRAPPER_SUFFIX: N = "$object"
118118
val LOCALDUMMY_PREFIX: N = "<local " // owner of local blocks
119119
val MODULE_SUFFIX: N = NameTransformer.MODULE_SUFFIX_STRING
120-
val MODULE_VAR_SUFFIX: N = "$module"
121120
val NAME_JOIN: N = NameTransformer.NAME_JOIN_STRING
122121
val OPS_PACKAGE: N = "<special-ops>"
123122
val OVERLOADED: N = "<overloaded>"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ object TastyFormat {
237237
final val DIRECT = 31
238238
final val FIELD = 32
239239
final val SETTER = 33
240+
final val OBJECTVAR = 39
240241
final val OBJECTCLASS = 40
241242

242243
final val SIGNED = 63

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
131131
toTextRHS(tp)
132132
case tp: TermRef
133133
if !tp.denotationIsCurrent && !homogenizedView || // always print underlying when testing picklers
134-
tp.symbol.is(Module) ||
135-
tp.symbol.name.isImportName =>
134+
tp.symbol.is(Module) || tp.symbol.name == nme.IMPORT =>
136135
toTextRef(tp) ~ ".type"
137136
case tp: TermRef if tp.denot.isOverloaded =>
138137
"<overloaded " ~ toTextRef(tp) ~ ">"

0 commit comments

Comments
 (0)