Skip to content

Commit 8b5154d

Browse files
committed
Make designator a union type
1 parent 7364f53 commit 8b5154d

File tree

7 files changed

+14
-16
lines changed

7 files changed

+14
-16
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,12 @@ object Names {
2020
*/
2121
type PreName = Name | String
2222

23-
/** A common superclass of Name and Symbol. After bootstrap, this should be
24-
* just the type alias Name | Symbol
25-
*/
26-
abstract class Designator
27-
2823
/** A name is either a term name or a type name. Term names can be simple
2924
* or derived. A simple term name is essentially an interned string stored
3025
* in a name table. A derived term name adds a tag, and possibly a number
3126
* or a further simple name to some other name.
3227
*/
33-
abstract class Name extends Designator, Showable derives CanEqual {
28+
abstract class Name extends Showable derives CanEqual {
3429

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2662,7 +2662,7 @@ object SymDenotations {
26622662
if (!traceInvalid(owner)) explainSym("owner is invalid")
26632663
else if (!owner.isClass || owner.isRefinementClass || denot.isSelfSym) true
26642664
else if (owner.unforcedDecls.lookupAll(denot.name) contains denot.symbol) true
2665-
else explainSym(s"decls of ${show(owner)} are ${owner.unforcedDecls.lookupAll(denot.name).toList}, do not contain ${denot.symbol}")
2665+
else explainSym(s"decls of ${show(owner)} are ${owner.unforcedDecls.lookupAll(denot.name).toList.map(show(_))}, do not contain ${denot.symbol}")
26662666
}
26672667
catch {
26682668
case ex: StaleSymbol => explainSym(s"$ex was thrown")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object Symbols {
4444
* @param id A unique identifier of the symbol (unique per ContextBase)
4545
*/
4646
class Symbol private[Symbols] (private var myCoord: Coord, val id: Int, val nestingLevel: Int)
47-
extends Designator, ParamInfo, SrcPos, printing.Showable {
47+
extends ParamInfo, SrcPos, printing.Showable {
4848

4949
type ThisName <: Name
5050

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,8 @@ object Types {
21792179

21802180
// --- NamedTypes ------------------------------------------------------------------
21812181

2182+
type Designator = Name | Symbol
2183+
21822184
abstract class NamedType extends CachedProxyType, ValueType { self =>
21832185

21842186
type ThisType >: this.type <: NamedType
@@ -2444,11 +2446,12 @@ object Types {
24442446
checkSymAssign(denot.symbol)
24452447

24462448
lastDenotation = denot
2447-
lastSymbol = denot.symbol
2449+
val lastSym = denot.symbol.asInstanceOf[Symbol]
2450+
lastSymbol = lastSym
24482451
checkedPeriod = if (prefix.isProvisional) Nowhere else ctx.period
24492452
designator match {
2450-
case sym: Symbol if designator ne lastSymbol.nn =>
2451-
designator = lastSymbol.asInstanceOf[Designator{ type ThisName = self.ThisName }]
2453+
case sym: Symbol if designator ne lastSym =>
2454+
designator = lastSym
24522455
case _ =>
24532456
}
24542457
checkDenot()

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import scala.collection.mutable
99
import core._
1010
import Texts._, Types._, Flags._, Symbols._, Contexts._
1111
import Decorators._
12+
import Names.Name
1213
import reporting.Message
1314
import util.DiffUtil
1415
import Highlighting._
@@ -22,7 +23,7 @@ object Formatting {
2223
* interpolator's correct context, that is with non-sensical tagging, message limiting, explanations, etc. */
2324
opaque type Shown = Any
2425
object Shown:
25-
given [A: Show]: Conversion[A, Shown] = Show[A].show(_)
26+
given toShown[A: Show]: Conversion[A, Shown] = Show[A].show(_)
2627

2728
sealed abstract class Show[-T]:
2829
/** Show a value T by returning a "shown" result. */
@@ -48,7 +49,6 @@ object Formatting {
4849

4950
class ShowImplicits1 extends ShowImplicits2:
5051
given Show[ImplicitRef] = ShowAny
51-
given Show[Names.Designator] = ShowAny
5252
given Show[util.SrcPos] = ShowAny
5353

5454
object Show extends ShowImplicits1:
@@ -90,6 +90,8 @@ object Formatting {
9090
given Show[util.SourceFile] = ShowAny
9191
given Show[util.Spans.Span] = ShowAny
9292
given Show[tasty.TreeUnpickler#OwnerTree] = ShowAny
93+
given Show[Name] = ShowAny
94+
given Show[Symbol] = ShowAny
9395

9496
private def show1[A: Show](x: A)(using Context) = show2(Show[A].show(x).ctxShow)
9597
private def show2(x: Shown)(using Context): String = x match

compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import core.Symbols.{ Symbol , defn, NoSymbol }
55
import core.Contexts._
66
import core.Names
77
import core.Names.Name
8-
import core.Types.{Type, TypeBounds}
8+
import core.Types.{Type, TypeBounds, Designator}
99
import core.Flags._
1010
import core.NameKinds
1111
import core.StdNames.nme
1212
import SymbolInformation.{Kind => k}
1313
import dotty.tools.dotc.util.SourceFile
1414
import dotty.tools.dotc.util.Spans.Span
15-
import dotty.tools.dotc.core.Names.Designator
1615

1716
import java.lang.Character.{isJavaIdentifierPart, isJavaIdentifierStart}
1817

compiler/src/dotty/tools/dotc/semanticdb/TypeOps.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import collection.mutable
1515

1616
import dotty.tools.dotc.{semanticdb => s}
1717
import Scala3.{FakeSymbol, SemanticSymbol, WildcardTypeSymbol, TypeParamRefSymbol, TermParamRefSymbol, RefinementSymbol}
18-
import dotty.tools.dotc.core.Names.Designator
1918

2019
class TypeOps:
2120
import SymbolScopeOps._

0 commit comments

Comments
 (0)