@@ -656,6 +656,15 @@ object Types {
656
656
if (res.exists) res else TypeRef (this , name, denot)
657
657
}
658
658
659
+ /** The type <this . name> , reduced if possible, with given denotation if unreduced */
660
+ def selectNonMember (name : Name , denot : Denotation )(implicit ctx : Context ): Type = name match {
661
+ case name : TermName =>
662
+ TermRef (this , name, denot)
663
+ case name : TypeName =>
664
+ val res = lookupRefined(name)
665
+ if (res.exists) res else TypeRef (this , name, denot)
666
+ }
667
+
659
668
/** The type <this . name> with given symbol, reduced if possible */
660
669
def select (sym : Symbol )(implicit ctx : Context ): Type =
661
670
if (sym.isTerm) TermRef (this , sym.asTerm)
@@ -991,6 +1000,8 @@ object Types {
991
1000
val prefix : Type
992
1001
val name : Name
993
1002
1003
+ type ThisType >: this .type <: NamedType
1004
+
994
1005
assert(prefix.isValueType || (prefix eq NoPrefix ), s " invalid prefix $prefix" )
995
1006
996
1007
private [this ] var lastDenotation : Denotation = _
@@ -1049,19 +1060,48 @@ object Types {
1049
1060
if (owner.isTerm) d else d.asSeenFrom(prefix)
1050
1061
}
1051
1062
1052
- private [dotc] final def withDenot (denot : Denotation ): this .type = {
1063
+ private def checkSymAssign (sym : Symbol ) =
1064
+ assert(
1065
+ (lastSymbol eq sym) ||
1066
+ (lastSymbol eq null ) ||
1067
+ (lastSymbol.defRunId != sym.defRunId) ||
1068
+ (lastSymbol.defRunId == NoRunId ),
1069
+ s " data race? overwriting symbol of $this / ${this .getClass} / ${lastSymbol.id} / ${sym.id}" )
1070
+
1071
+ protected def sig : Signature = Signature .NotAMethod
1072
+
1073
+ private [dotc] def withDenot (denot : Denotation )(implicit ctx : Context ): ThisType =
1074
+ if (sig != denot.signature)
1075
+ withSig(denot.signature).withDenot(denot).asInstanceOf [ThisType ]
1076
+ else {
1077
+ setDenot(denot)
1078
+ this
1079
+ }
1080
+
1081
+ private [dotc] final def setDenot (denot : Denotation ): Unit = {
1082
+ if (Config .checkTermRefs) checkSymAssign(denot.symbol)
1053
1083
lastDenotation = denot
1054
1084
lastSymbol = denot.symbol
1055
- this
1056
1085
}
1057
1086
1058
- private [dotc] final def withSym (sym : Symbol ): this .type = {
1087
+ private [dotc] def withSym (sym : Symbol , signature : Signature )(implicit ctx : Context ): ThisType =
1088
+ if (sig != signature)
1089
+ withSig(signature).withSym(sym, signature).asInstanceOf [ThisType ]
1090
+ else {
1091
+ setSym(sym)
1092
+ this
1093
+ }
1094
+
1095
+ private [dotc] final def setSym (sym : Symbol ): Unit = {
1096
+ if (Config .checkTermRefs) checkSymAssign(sym)
1059
1097
lastDenotation = null
1060
1098
lastSymbol = sym
1061
1099
checkedPeriod = Nowhere
1062
- this
1063
1100
}
1064
1101
1102
+ private def withSig (sig : Signature )(implicit ctx : Context ): NamedType =
1103
+ TermRef .withSig(prefix, name.asTermName, sig)
1104
+
1065
1105
protected def loadDenot (implicit ctx : Context ) = {
1066
1106
val d = prefix.member(name)
1067
1107
if (d.exists || ctx.phaseId == FirstPhaseId )
@@ -1136,6 +1176,9 @@ object Types {
1136
1176
1137
1177
abstract case class TermRef (override val prefix : Type , name : TermName ) extends NamedType with SingletonType {
1138
1178
1179
+ type ThisType = TermRef
1180
+
1181
+ // assert(name.toString != "<local Coder>")
1139
1182
override def underlying (implicit ctx : Context ): Type = {
1140
1183
val d = denot
1141
1184
if (d.isOverloaded) NoType else d.info
@@ -1156,16 +1199,31 @@ object Types {
1156
1199
}
1157
1200
1158
1201
abstract case class TypeRef (override val prefix : Type , name : TypeName ) extends NamedType {
1202
+
1203
+ type ThisType = TypeRef
1204
+
1159
1205
override def underlying (implicit ctx : Context ): Type = info
1160
1206
}
1161
1207
1162
- final class TermRefWithSignature (prefix : Type , name : TermName , val sig : Signature ) extends TermRef (prefix, name) {
1208
+ final class TermRefWithSignature (prefix : Type , name : TermName , override val sig : Signature ) extends TermRef (prefix, name) {
1163
1209
assert(prefix ne NoPrefix )
1164
1210
override def signature (implicit ctx : Context ) = sig
1165
- override def loadDenot (implicit ctx : Context ): Denotation =
1166
- super .loadDenot.atSignature(sig)
1167
- override def newLikeThis (prefix : Type )(implicit ctx : Context ): TermRef =
1168
- TermRef .withSig(prefix, name, sig)
1211
+ override def loadDenot (implicit ctx : Context ): Denotation = {
1212
+ val d = super .loadDenot
1213
+ if (sig eq Signature .OverloadedSignature ) d
1214
+ else d.atSignature(sig)
1215
+ }
1216
+
1217
+ override def newLikeThis (prefix : Type )(implicit ctx : Context ): TermRef = {
1218
+ if (sig != Signature .NotAMethod &&
1219
+ sig != Signature .OverloadedSignature &&
1220
+ symbol.exists) {
1221
+ val ownSym = symbol
1222
+ TermRef (prefix, name).withDenot(prefix.member(name).disambiguate(_ eq ownSym))
1223
+ }
1224
+ else TermRef .withSig(prefix, name, sig)
1225
+ }
1226
+
1169
1227
override def equals (that : Any ) = that match {
1170
1228
case that : TermRefWithSignature =>
1171
1229
this .prefix == that.prefix &&
@@ -1177,15 +1235,25 @@ object Types {
1177
1235
override def computeHash = doHash((name, sig), prefix)
1178
1236
}
1179
1237
1180
- trait WithNoPrefix extends NamedType {
1238
+ trait WithNonMemberSym extends NamedType {
1181
1239
def fixedSym : Symbol
1182
1240
assert(fixedSym ne NoSymbol )
1183
- withSym(fixedSym)
1241
+ setSym(fixedSym)
1242
+
1243
+ override def withDenot (denot : Denotation )(implicit ctx : Context ): ThisType = {
1244
+ assert(denot.symbol eq fixedSym)
1245
+ setDenot(denot)
1246
+ this
1247
+ }
1248
+
1249
+ override def withSym (sym : Symbol , signature : Signature )(implicit ctx : Context ): ThisType =
1250
+ unsupported(" withSym" )
1251
+
1184
1252
override def equals (that : Any ) = that match {
1185
- case that : WithNoPrefix => this .fixedSym eq that.fixedSym
1253
+ case that : WithNonMemberSym => this .prefix == that.prefix && ( this . fixedSym eq that.fixedSym)
1186
1254
case _ => false
1187
1255
}
1188
- override def computeHash = doHash(fixedSym)
1256
+ override def computeHash = doHash(fixedSym, prefix )
1189
1257
}
1190
1258
1191
1259
final class CachedTermRef (prefix : Type , name : TermName , hc : Int ) extends TermRef (prefix, name) {
@@ -1200,8 +1268,8 @@ object Types {
1200
1268
override def computeHash = unsupported(" computeHash" )
1201
1269
}
1202
1270
1203
- final class NoPrefixTermRef ( name : TermName , val fixedSym : TermSymbol ) extends TermRef (NoPrefix , name) with WithNoPrefix
1204
- final class NoPrefixTypeRef ( name : TypeName , val fixedSym : TypeSymbol ) extends TypeRef (NoPrefix , name) with WithNoPrefix
1271
+ final class NonMemberTermRef ( prefix : Type , name : TermName , val fixedSym : TermSymbol ) extends TermRef (prefix , name) with WithNonMemberSym
1272
+ final class NonMemberTypeRef ( prefix : Type , name : TypeName , val fixedSym : TypeSymbol ) extends TypeRef (prefix , name) with WithNonMemberSym
1205
1273
1206
1274
object NamedType {
1207
1275
def apply (prefix : Type , name : Name )(implicit ctx : Context ) =
@@ -1210,20 +1278,42 @@ object Types {
1210
1278
def apply (prefix : Type , name : Name , denot : Denotation )(implicit ctx : Context ) =
1211
1279
if (name.isTermName) TermRef (prefix, name.asTermName, denot)
1212
1280
else TypeRef (prefix, name.asTypeName, denot)
1281
+ def withNonMemberSym (prefix : Type , sym : Symbol )(implicit ctx : Context ) =
1282
+ if (sym.isType) TypeRef .withNonMemberSym(prefix, sym.name.asTypeName, sym.asType)
1283
+ else TermRef .withNonMemberSym(prefix, sym.name.asTermName, sym.asTerm)
1213
1284
}
1214
1285
1215
1286
object TermRef {
1216
1287
def apply (prefix : Type , name : TermName )(implicit ctx : Context ): TermRef =
1217
1288
ctx.uniqueNamedTypes.enterIfNew(prefix, name).asInstanceOf [TermRef ]
1289
+
1218
1290
def apply (prefix : Type , sym : TermSymbol )(implicit ctx : Context ): TermRef =
1219
1291
withSymAndName(prefix, sym, sym.name)
1292
+
1293
+ def apply (prefix : Type , name : TermName , denot : Denotation )(implicit ctx : Context ): TermRef = {
1294
+ if (prefix eq NoPrefix ) apply(prefix, denot.symbol.asTerm)
1295
+ else denot match {
1296
+ case denot : SymDenotation if denot.isCompleted => withSig(prefix, name, denot.signature)
1297
+ case _ => apply(prefix, name)
1298
+ }
1299
+ } withDenot denot
1300
+
1301
+ def withNonMemberSym (prefix : Type , name : TermName , sym : TermSymbol )(implicit ctx : Context ): TermRef =
1302
+ unique(new NonMemberTermRef (prefix, name, sym))
1303
+
1220
1304
def withSymAndName (prefix : Type , sym : TermSymbol , name : TermName )(implicit ctx : Context ): TermRef =
1221
- if (prefix eq NoPrefix ) unique(new NoPrefixTermRef (name, sym))
1222
- else apply(prefix, name) withSym sym
1223
- def apply (prefix : Type , name : TermName , denot : Denotation )(implicit ctx : Context ): TermRef =
1224
- (if (prefix eq NoPrefix ) apply(prefix, denot.symbol.asTerm) else apply(prefix, name)) withDenot denot
1305
+ if (prefix eq NoPrefix ) withNonMemberSym(prefix, name, sym)
1306
+ else {
1307
+ if (sym.defRunId != NoRunId && sym.isCompleted) withSig(prefix, name, sym.signature)
1308
+ else apply(prefix, name)
1309
+ } withSym (sym, Signature .NotAMethod )
1310
+
1311
+ def withSig (prefix : Type , sym : TermSymbol )(implicit ctx : Context ): TermRef =
1312
+ unique(withSig(prefix, sym.name, sym.signature).withSym(sym, sym.signature))
1313
+
1225
1314
def withSig (prefix : Type , name : TermName , sig : Signature )(implicit ctx : Context ): TermRef =
1226
1315
unique(new TermRefWithSignature (prefix, name, sig))
1316
+
1227
1317
def withSig (prefix : Type , name : TermName , sig : Signature , denot : Denotation )(implicit ctx : Context ): TermRef =
1228
1318
(if (prefix eq NoPrefix ) apply(prefix, denot.symbol.asTerm)
1229
1319
else withSig(prefix, name, sig)) withDenot denot
@@ -1232,11 +1322,17 @@ object Types {
1232
1322
object TypeRef {
1233
1323
def apply (prefix : Type , name : TypeName )(implicit ctx : Context ): TypeRef =
1234
1324
ctx.uniqueNamedTypes.enterIfNew(prefix, name).asInstanceOf [TypeRef ]
1325
+
1235
1326
def apply (prefix : Type , sym : TypeSymbol )(implicit ctx : Context ): TypeRef =
1236
1327
withSymAndName(prefix, sym, sym.name)
1328
+
1329
+ def withNonMemberSym (prefix : Type , name : TypeName , sym : TypeSymbol )(implicit ctx : Context ): TypeRef =
1330
+ unique(new NonMemberTypeRef (prefix, name, sym))
1331
+
1237
1332
def withSymAndName (prefix : Type , sym : TypeSymbol , name : TypeName )(implicit ctx : Context ): TypeRef =
1238
- if (prefix eq NoPrefix ) unique(new NoPrefixTypeRef (name, sym))
1239
- else apply(prefix, name) withSym sym
1333
+ if (prefix eq NoPrefix ) withNonMemberSym(prefix, name, sym)
1334
+ else apply(prefix, name).withSym(sym, Signature .NotAMethod )
1335
+
1240
1336
def apply (prefix : Type , name : TypeName , denot : Denotation )(implicit ctx : Context ): TypeRef =
1241
1337
(if (prefix eq NoPrefix ) apply(prefix, denot.symbol.asType) else apply(prefix, name)) withDenot denot
1242
1338
}
0 commit comments