diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala index 52a0cbb735b5..a3f021001158 100644 --- a/compiler/src/dotty/tools/dotc/core/NameOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala @@ -49,7 +49,7 @@ object NameOps { } } - implicit class NameDecorator[N <: Name](val name: N) extends AnyVal { + implicit class NameDecorator[N <: Name](private val name: N) extends AnyVal { import nme._ def testSimple(f: SimpleName => Boolean): Boolean = name match { @@ -58,8 +58,8 @@ object NameOps { case _ => false } - def likeSpaced(n: PreName): N = - (if (name.isTermName) n.toTermName else n.toTypeName).asInstanceOf[N] + private def likeSpacedN(n: Name): N = + name.likeSpaced(n).asInstanceOf[N] def isConstructorName = name == CONSTRUCTOR || name == TRAIT_CONSTRUCTOR def isStaticConstructorName = name == STATIC_CONSTRUCTOR @@ -100,7 +100,7 @@ object NameOps { * method needs to work on mangled as well as unmangled names because * it is also called from the backend. */ - def stripModuleClassSuffix: N = likeSpaced { + def stripModuleClassSuffix: N = likeSpacedN { val semName = name.toTermName match { case name: SimpleName if name.endsWith("$") => name.unmangleClassName case _ => name @@ -109,7 +109,7 @@ object NameOps { } /** If flags is a ModuleClass but not a Package, add module class suffix */ - def adjustIfModuleClass(flags: Flags.FlagSet): N = likeSpaced { + def adjustIfModuleClass(flags: Flags.FlagSet): N = likeSpacedN { if (flags is (ModuleClass, butNot = Package)) name.asTypeName.moduleClassName else name.toTermName.exclude(AvoidClashName) } @@ -119,27 +119,27 @@ object NameOps { * followed by `kind` and the name. */ def expandedName(base: Symbol, kind: QualifiedNameKind = ExpandedName)(implicit ctx: Context): N = - likeSpaced { base.fullNameSeparated(ExpandPrefixName, kind, name) } + likeSpacedN { base.fullNameSeparated(ExpandPrefixName, kind, name) } /** Revert the expanded name. */ - def unexpandedName: N = likeSpaced { + def unexpandedName: N = likeSpacedN { name.rewrite { case ExpandedName(_, unexp) => unexp } } /** Remove the variance from the name. */ - def invariantName: N = likeSpaced { + def invariantName: N = likeSpacedN { name.rewrite { case VariantName(invariant, _) => invariant } } - def implClassName: N = likeSpaced(name ++ tpnme.IMPL_CLASS_SUFFIX) + def implClassName: N = likeSpacedN(name ++ tpnme.IMPL_CLASS_SUFFIX) def traitOfImplClassName: N = { val suffix = tpnme.IMPL_CLASS_SUFFIX.toString assert(name.endsWith(suffix), name) - likeSpaced(name.mapLast(_.dropRight(suffix.length))) + likeSpacedN(name.mapLast(_.dropRight(suffix.length))) } - def errorName: N = likeSpaced(name ++ nme.ERROR) + def errorName: N = likeSpacedN(name ++ nme.ERROR) /** Map variance value -1, +1 to 0, 1 */ private def varianceToNat(v: Int) = (v + 1) / 2 @@ -150,7 +150,7 @@ object NameOps { /** Name with variance prefix: `+` for covariant, `-` for contravariant */ def withVariance(v: Int): N = { val underlying = name.exclude(VariantName) - likeSpaced( + likeSpacedN( if (v == 0) underlying else VariantName(underlying.toTermName, varianceToNat(v))) } @@ -160,7 +160,7 @@ object NameOps { */ def variance = name.collect { case VariantName(_, n) => natToVariance(n) }.getOrElse(0) - def freshened(implicit ctx: Context): N = likeSpaced { + def freshened(implicit ctx: Context): N = likeSpacedN { name.toTermName match { case ModuleClassName(original) => ModuleClassName(original.freshened) case name => UniqueName.fresh(name) @@ -233,12 +233,12 @@ object NameOps { case nme.clone_ => nme.clone_ } - def specializedFor(classTargs: List[Types.Type], classTargsNames: List[Name], methodTargs: List[Types.Type], methodTarsNames: List[Name])(implicit ctx: Context): name.ThisName = { + def specializedFor(classTargs: List[Types.Type], classTargsNames: List[Name], methodTargs: List[Types.Type], methodTarsNames: List[Name])(implicit ctx: Context): N = { val methodTags: Seq[Name] = (methodTargs zip methodTarsNames).sortBy(_._2).map(x => defn.typeTag(x._1)) val classTags: Seq[Name] = (classTargs zip classTargsNames).sortBy(_._2).map(x => defn.typeTag(x._1)) - name.likeSpaced(name ++ nme.specializedTypeNames.prefix ++ + likeSpacedN(name ++ nme.specializedTypeNames.prefix ++ methodTags.fold(nme.EMPTY)(_ ++ _) ++ nme.specializedTypeNames.separator ++ classTags.fold(nme.EMPTY)(_ ++ _) ++ nme.specializedTypeNames.suffix) } @@ -249,11 +249,11 @@ object NameOps { def unmangleClassName: N = name.toTermName match { case name: SimpleName if name.endsWith(str.MODULE_SUFFIX) && !nme.falseModuleClassNames.contains(name) => - likeSpaced(name.dropRight(str.MODULE_SUFFIX.length).moduleClassName) + likeSpacedN(name.dropRight(str.MODULE_SUFFIX.length).moduleClassName) case _ => name } - def unmangle(kind: NameKind): N = likeSpaced { + def unmangle(kind: NameKind): N = likeSpacedN { name rewrite { case unmangled: SimpleName => kind.unmangle(unmangled) @@ -271,7 +271,7 @@ object NameOps { } } - implicit class TermNameDecorator(val name: TermName) extends AnyVal { + implicit class TermNameDecorator(private val name: TermName) extends AnyVal { import nme._ def setterName: TermName = name.exclude(FieldName) ++ str.SETTER_SUFFIX diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 2df2e49e85e2..818e38ffb4b7 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1260,26 +1260,26 @@ object messages { |""".stripMargin } - case class OverloadedOrRecursiveMethodNeedsResultType(tree: Names.TermName)(implicit ctx: Context) + case class OverloadedOrRecursiveMethodNeedsResultType(method: Names.TermName)(implicit ctx: Context) extends Message(OverloadedOrRecursiveMethodNeedsResultTypeID) { val kind = "Syntax" - val msg = hl"""overloaded or recursive method ${tree} needs return type""" + val msg = hl"""overloaded or recursive method ${method} needs return type""" val explanation = - hl"""Case 1: ${tree} is overloaded - |If there are multiple methods named `${tree.name}` and at least one definition of + hl"""Case 1: ${method} is overloaded + |If there are multiple methods named `${method}` and at least one definition of |it calls another, you need to specify the calling method's return type. | - |Case 2: ${tree} is recursive - |If `${tree.name}` calls itself on any path, you need to specify its return type. + |Case 2: ${method} is recursive + |If `${method}` calls itself on any path, you need to specify its return type. |""".stripMargin } - case class RecursiveValueNeedsResultType(tree: Names.TermName)(implicit ctx: Context) + case class RecursiveValueNeedsResultType(value: Names.TermName)(implicit ctx: Context) extends Message(RecursiveValueNeedsResultTypeID) { val kind = "Syntax" - val msg = hl"""recursive value ${tree.name} needs type""" + val msg = hl"""recursive value ${value} needs type""" val explanation = - hl"""The definition of `${tree.name}` is recursive and you need to specify its type. + hl"""The definition of `${value}` is recursive and you need to specify its type. |""".stripMargin }