Skip to content

Commit 6f53e62

Browse files
committed
Stop accidental support for .name on Name
This is easy for `NameDecorator`, but use of path-dependent types in `NameDecorator` makes this tricky (see code), and you can still call `name_` on Names. Hopefully that jumps more to the eye or we can pick an ever worse name.
1 parent b9539b7 commit 6f53e62

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ object NameOps {
4949
}
5050
}
5151

52-
implicit class NameDecorator[N <: Name](val name: N) extends AnyVal {
52+
implicit class NameDecorator[N <: Name](val name_ : N) extends AnyVal {
53+
private def name = name_
5354
import nme._
5455

5556
def testSimple(f: SimpleName => Boolean): Boolean = name match {
@@ -233,12 +234,12 @@ object NameOps {
233234
case nme.clone_ => nme.clone_
234235
}
235236

236-
def specializedFor(classTargs: List[Types.Type], classTargsNames: List[Name], methodTargs: List[Types.Type], methodTarsNames: List[Name])(implicit ctx: Context): name.ThisName = {
237+
def specializedFor(classTargs: List[Types.Type], classTargsNames: List[Name], methodTargs: List[Types.Type], methodTarsNames: List[Name])(implicit ctx: Context): name_.ThisName = {
237238

238239
val methodTags: Seq[Name] = (methodTargs zip methodTarsNames).sortBy(_._2).map(x => defn.typeTag(x._1))
239240
val classTags: Seq[Name] = (classTargs zip classTargsNames).sortBy(_._2).map(x => defn.typeTag(x._1))
240241

241-
name.likeSpaced(name ++ nme.specializedTypeNames.prefix ++
242+
name_.likeSpaced(name ++ nme.specializedTypeNames.prefix ++
242243
methodTags.fold(nme.EMPTY)(_ ++ _) ++ nme.specializedTypeNames.separator ++
243244
classTags.fold(nme.EMPTY)(_ ++ _) ++ nme.specializedTypeNames.suffix)
244245
}
@@ -271,7 +272,7 @@ object NameOps {
271272
}
272273
}
273274

274-
implicit class TermNameDecorator(val name: TermName) extends AnyVal {
275+
implicit class TermNameDecorator(private val name: TermName) extends AnyVal {
275276
import nme._
276277

277278
def setterName: TermName = name.exclude(FieldName) ++ str.SETTER_SUFFIX

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,20 +1266,20 @@ object messages {
12661266
val msg = hl"""overloaded or recursive method ${tree} needs return type"""
12671267
val explanation =
12681268
hl"""Case 1: ${tree} is overloaded
1269-
|If there are multiple methods named `${tree.name}` and at least one definition of
1269+
|If there are multiple methods named `${tree}` and at least one definition of
12701270
|it calls another, you need to specify the calling method's return type.
12711271
|
12721272
|Case 2: ${tree} is recursive
1273-
|If `${tree.name}` calls itself on any path, you need to specify its return type.
1273+
|If `${tree}` calls itself on any path, you need to specify its return type.
12741274
|""".stripMargin
12751275
}
12761276

12771277
case class RecursiveValueNeedsResultType(tree: Names.TermName)(implicit ctx: Context)
12781278
extends Message(RecursiveValueNeedsResultTypeID) {
12791279
val kind = "Syntax"
1280-
val msg = hl"""recursive value ${tree.name} needs type"""
1280+
val msg = hl"""recursive value ${tree} needs type"""
12811281
val explanation =
1282-
hl"""The definition of `${tree.name}` is recursive and you need to specify its type.
1282+
hl"""The definition of `${tree}` is recursive and you need to specify its type.
12831283
|""".stripMargin
12841284
}
12851285

0 commit comments

Comments
 (0)