Skip to content

Commit 12cd6bb

Browse files
committed
Make desigantors of WithFixedSym classes symbols
Thsi will be cleaned up further in next commit.
1 parent f7a81e2 commit 12cd6bb

File tree

9 files changed

+34
-27
lines changed

9 files changed

+34
-27
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,11 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
431431
var found = desugared.get(i.tpe)
432432
if (found == null) {
433433
i.tpe match {
434-
case TermRef(prefix: TermRef, name) =>
434+
case TermRef(prefix: TermRef, _) =>
435435
found = tpd.ref(prefix).select(i.symbol)
436-
case TermRef(prefix: ThisType, name) =>
436+
case TermRef(prefix: ThisType, _) =>
437437
found = tpd.This(prefix.cls).select(i.symbol)
438-
case TermRef(NoPrefix, name) =>
438+
case TermRef(NoPrefix, _) =>
439439
if (i.symbol is Flags.Method) found = This(i.symbol.topLevelClass).select(i.symbol) // workaround #342 todo: remove after fixed
440440
case _ =>
441441
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
164164
ctx.typeComparer.lubArgs(args1, args2, tycon1.typeParams))
165165
case _ => fail
166166
}
167-
case tp1 @ TypeRef(pre1, name1) =>
167+
case tp1 @ TypeRef(pre1, _) =>
168168
tp2 match {
169-
case tp2 @ TypeRef(pre2, `name1`) =>
169+
case tp2 @ TypeRef(pre2, _) if tp1.name eq tp2.name =>
170170
tp1.derivedSelect(pre1 | pre2)
171171
case _ => fail
172172
}

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,12 +1746,11 @@ object Types {
17461746
def reloadDenot()(implicit ctx: Context) = setDenot(loadDenot)
17471747

17481748
protected def asMemberOf(prefix: Type, allowPrivate: Boolean)(implicit ctx: Context): Denotation = {
1749-
def recur(desig: Name): Denotation =
1750-
if (desig.is(SignedName)) recur(name)
1751-
else if (desig.is(ShadowedName)) prefix.nonPrivateMember(desig.exclude(ShadowedName))
1752-
else if (!allowPrivate) prefix.nonPrivateMember(desig)
1753-
else prefix.member(desig)
1754-
recur(designatorName)
1749+
def recur(name: Name): Denotation =
1750+
if (name.is(ShadowedName)) prefix.nonPrivateMember(name.exclude(ShadowedName))
1751+
else if (!allowPrivate) prefix.nonPrivateMember(name)
1752+
else prefix.member(name)
1753+
recur(name)
17551754
}
17561755

17571756
/** (1) Reduce a type-ref `W # X` or `W { ... } # U`, where `W` is a wildcard type
@@ -2006,7 +2005,8 @@ object Types {
20062005

20072006

20082007
trait WithFixedSym extends NamedType {
2009-
def fixedSym: Symbol
2008+
def fixedSym: Symbol = designator.asInstanceOf[Symbol]
2009+
assert(fixedSym ne null)
20102010
assert(fixedSym ne NoSymbol)
20112011
uncheckedSetSym(fixedSym)
20122012

@@ -2027,6 +2027,13 @@ object Types {
20272027
case _ => false
20282028
}
20292029
override def computeHash = unsupported("computeHash")
2030+
2031+
def checkInst(n: Name, sym: Symbol)(implicit ctx: Context): this.type = {
2032+
//assert(name == n, i"bad name: ${name.debugString}, expected: ${n.debugString}, ${System.identityHashCode(name)}, ${System.identityHashCode(n)}")
2033+
//assert(fixedSym eq sym)
2034+
//assert(symbol eq sym)
2035+
this
2036+
}
20302037
}
20312038

20322039
final class CachedTermRef(prefix: Type, designator: TermDesignator, hc: Int) extends TermRef(prefix, designator) {
@@ -2042,10 +2049,10 @@ object Types {
20422049
}
20432050

20442051
// Those classes are non final as Linker extends them.
2045-
class TermRefWithFixedSym(prefix: Type, designator: TermName, val fixedSym: TermSymbol, hc: Int) extends TermRef(prefix, designator) with WithFixedSym {
2052+
class TermRefWithFixedSym(prefix: Type, d: Name, designator: TermSymbol, hc: Int) extends TermRef(prefix, designator) with WithFixedSym {
20462053
myHash = hc
20472054
}
2048-
class TypeRefWithFixedSym(prefix: Type, designator: TypeName, val fixedSym: TypeSymbol, hc: Int) extends TypeRef(prefix, designator) with WithFixedSym {
2055+
class TypeRefWithFixedSym(prefix: Type, d: Name, designator: TypeSymbol, hc: Int) extends TypeRef(prefix, designator) with WithFixedSym {
20492056
myHash = hc
20502057
}
20512058

@@ -2103,7 +2110,7 @@ object Types {
21032110
* with given prefix, name, and signature
21042111
*/
21052112
def withFixedSym(prefix: Type, name: TermName, sym: TermSymbol)(implicit ctx: Context): TermRef =
2106-
ctx.uniqueWithFixedSyms.enterIfNew(prefix, name, sym).asInstanceOf[TermRef]
2113+
ctx.uniqueWithFixedSyms.enterIfNew(prefix, name, sym).asInstanceOf[TermRefWithFixedSym].checkInst(name, sym)
21072114

21082115
/** Create a term ref referring to given symbol with given name, taking the signature
21092116
* from the symbol if it is completed, or creating a term ref without
@@ -2157,7 +2164,7 @@ object Types {
21572164
* with given prefix, name, and symbol.
21582165
*/
21592166
def withFixedSym(prefix: Type, name: TypeName, sym: TypeSymbol)(implicit ctx: Context): TypeRef =
2160-
ctx.uniqueWithFixedSyms.enterIfNew(prefix, name, sym).asInstanceOf[TypeRef]
2167+
ctx.uniqueWithFixedSyms.enterIfNew(prefix, name, sym).asInstanceOf[TypeRefWithFixedSym].checkInst(name, sym)
21612168

21622169
/** Create a type ref referring to given symbol with given name.
21632170
* This is very similar to TypeRef(Type, Symbol),
@@ -2374,7 +2381,7 @@ object Types {
23742381
normalize(tp.parent.substRecThis(tp, rt.recThis))
23752382
case tp @ RefinedType(parent, rname, rinfo) =>
23762383
val rinfo1 = rinfo match {
2377-
case TypeAlias(TypeRef(RecThis(`rt`), `rname`)) => TypeBounds.empty
2384+
case TypeAlias(ref @ TypeRef(RecThis(`rt`), _)) if ref.name == rname => TypeBounds.empty
23782385
case _ => rinfo
23792386
}
23802387
tp.derivedRefinedType(normalize(parent), rname, rinfo1)
@@ -2682,7 +2689,7 @@ object Types {
26822689
if (dependencyStatus == FalseDeps) { // dealias all false dependencies
26832690
val dealiasMap = new TypeMap {
26842691
def apply(tp: Type) = tp match {
2685-
case tp @ TypeRef(pre, name) =>
2692+
case tp @ TypeRef(pre, _) =>
26862693
tp.info match {
26872694
case TypeAlias(alias) if depStatus(NoDeps, pre) == TrueDeps => apply(alias)
26882695
case _ => mapOver(tp)
@@ -4432,7 +4439,7 @@ object Types {
44324439
) map (_.toTypeName)
44334440

44344441
def isWatched(tp: Type) = tp match {
4435-
case TypeRef(_, name) => watchList contains name
4442+
case ref: TypeRef => watchList contains ref.name
44364443
case _ => false
44374444
}
44384445

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
630630
// unless names match up.
631631
val isBound = (tp: Type) => {
632632
def refersTo(tp: Type, sym: Symbol): Boolean = tp match {
633-
case tp @ TypeRef(_, name) => sym.name == name && sym == tp.symbol
633+
case tp: TypeRef => sym.name == tp.name && sym == tp.symbol
634634
case tp: TypeVar => refersTo(tp.underlying, sym)
635635
case tp : LazyRef => refersTo(tp.ref, sym)
636636
case _ => false

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ object PatternMatcher {
757757
// See the test for SI-7214 for motivation for dealias. Later `treeCondStrategy#outerTest`
758758
// generates an outer test based on `patType.prefix` with automatically dealises.
759759
expectedTp.dealias match {
760-
case tref @ TypeRef(pre: SingletonType, name) =>
760+
case tref @ TypeRef(pre: SingletonType, _) =>
761761
tref.symbol.isClass &&
762762
ExplicitOuter.needsOuterIfReferenced(tref.symbol.asClass)
763763
case _ =>

compiler/src/dotty/tools/dotc/transform/PatternMatcherOld.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ class PatternMatcherOld extends MiniPhaseTransform with DenotTransformer {
799799
// See the test for SI-7214 for motivation for dealias. Later `treeCondStrategy#outerTest`
800800
// generates an outer test based on `patType.prefix` with automatically dealises.
801801
expectedTp.dealias match {
802-
case tref @ TypeRef(pre: SingletonType, name) =>
802+
case tref @ TypeRef(pre: SingletonType, _) =>
803803
val s = tref
804804
s.symbol.isClass &&
805805
ExplicitOuter.needsOuterIfReferenced(s.symbol.asClass)

compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ object Simplify {
148148
// TODO: This function is duplicated in jvm/DottyBackendInterface.scala, let's factor these out!
149149
def desugarIdent(i: Ident)(implicit ctx: Context): Option[Select] = {
150150
i.tpe match {
151-
case TermRef(prefix: TermRef, name) =>
151+
case TermRef(prefix: TermRef, _) =>
152152
Some(ref(prefix).select(i.symbol))
153-
case TermRef(prefix: ThisType, name) =>
153+
case TermRef(prefix: ThisType, _) =>
154154
Some(This(prefix.cls).select(i.symbol))
155155
case _ => None
156156
}

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ object Checking {
219219
tp.derivedRefinedType(this(parent), name, this(rinfo, nestedCycleOK, nestedCycleOK))
220220
case tp: RecType =>
221221
tp.rebind(this(tp.parent))
222-
case tp @ TypeRef(pre, name) =>
222+
case tp @ TypeRef(pre, _) =>
223223
try {
224224
// A prefix is interesting if it might contain (transitively) a reference
225225
// to symbol `sym` itself. We only check references with interesting

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,9 +924,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
924924
val indexPattern = new TreeMap {
925925
val elimWildcardSym = new TypeMap {
926926
def apply(t: Type) = t match {
927-
case ref @ TypeRef(_, tpnme.WILDCARD) if ctx.gadt.bounds.contains(ref.symbol) =>
927+
case ref: TypeRef if ref.name == tpnme.WILDCARD && ctx.gadt.bounds.contains(ref.symbol) =>
928928
ctx.gadt.bounds(ref.symbol)
929-
case TypeAlias(ref @ TypeRef(_, tpnme.WILDCARD)) if ctx.gadt.bounds.contains(ref.symbol) =>
929+
case TypeAlias(ref: TypeRef) if ref.name == tpnme.WILDCARD && ctx.gadt.bounds.contains(ref.symbol) =>
930930
ctx.gadt.bounds(ref.symbol)
931931
case _ =>
932932
mapOver(t)

0 commit comments

Comments
 (0)