Skip to content

Commit 76bdfce

Browse files
Merge pull request #9273 from dotty-staging/drop-conversions-1
Drop PreName and its associated implicit conversions
2 parents 25a48dd + b21c1e4 commit 76bdfce

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ import printing.Formatting._
1515
/** This object provides useful implicit decorators for types defined elsewhere */
1616
object Decorators {
1717

18-
/** Turns Strings into PreNames, adding toType/TermName methods */
19-
implicit class PreNamedString(val s: String) extends AnyVal with PreName {
20-
def toTypeName: TypeName = typeName(s)
21-
def toTermName: TermName = termName(s)
22-
def toText(printer: Printer): Text = Str(s)
23-
}
18+
/** Extension methods for toType/TermName methods on strings.
19+
* They are in an implicit object for now, so that we can import decorators
20+
* with a normal wildcard. In the future, once #9255 is in trunk, replace with
21+
* a simple collective extension.
22+
*/
23+
implicit object PreNamedString:
24+
def (pn: PreName).toTypeName: TypeName = pn match
25+
case s: String => typeName(s)
26+
case n: Name => n.toTypeName
27+
def (pn: PreName).toTermName: TermName = pn match
28+
case s: String => termName(s)
29+
case n: Name => n.toTermName
2430

2531
implicit class StringDecorator(val s: String) extends AnyVal {
2632
def splitWhere(f: Char => Boolean, doDropIndex: Boolean): Option[(String, String)] = {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ class Definitions {
853853
"lombok.NonNull" ::
854854
"reactor.util.annotation.NonNull" ::
855855
"reactor.util.annotation.NonNullApi" ::
856-
"io.reactivex.annotations.NonNull" :: Nil map PreNamedString)
856+
"io.reactivex.annotations.NonNull" :: Nil)
857857

858858
// convenient one-parameter method types
859859
def methOfAny(tp: Type): MethodType = MethodType(List(AnyType), tp)

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

+4-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ import scala.annotation.internal.sharable
1717
object Names {
1818
import NameKinds._
1919

20-
/** A common class for things that can be turned into names.
21-
* Instances are both names and strings, the latter via a decorator.
20+
/** Things that can be turned into names with `totermName` and `toTypeName`
21+
* Decorators defines implements these as extension methods for strings.
2222
*/
23-
trait PreName extends Any with Showable {
24-
def toTypeName: TypeName
25-
def toTermName: TermName
26-
}
23+
type PreName = Name | String
2724

2825
/** A common superclass of Name and Symbol. After bootstrap, this should be
2926
* just the type alias Name | Symbol
@@ -35,7 +32,7 @@ object Names {
3532
* in a name table. A derived term name adds a tag, and possibly a number
3633
* or a further simple name to some other name.
3734
*/
38-
abstract class Name extends Designator, PreName derives Eql {
35+
abstract class Name extends Designator, Showable derives Eql {
3936

4037
/** A type for names of the same kind as this name */
4138
type ThisName <: Name

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import config.Config
99
import Contexts._, Symbols._, Flags._, SymDenotations._, Types._, Scopes._, Names._
1010
import NameOps._
1111
import StdNames.str
12-
import Decorators.{PreNamedString, StringInterpolators}
12+
import Decorators.StringInterpolators
1313
import classfile.ClassfileParser
1414
import util.Stats
1515
import Decorators._

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ object messages {
326326
// to the name of the missing member
327327
def closest: List[(Int, String)] = candidates
328328
.toList
329-
.map(n => (distance(n.show, missing), n))
329+
.map(n => (distance(n, missing), n))
330330
.filter((d, n) => d <= maxDist && d < missing.length && d < n.length)
331331
.sorted // sort by distance first, alphabetically second
332332

0 commit comments

Comments
 (0)