Skip to content

Commit c56c3aa

Browse files
committed
Make type parameter reordering generally available.
1 parent 8c18106 commit c56c3aa

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,23 @@ object SymDenotations {
14901490
if (myMemberCache != null) myMemberCache invalidate sym.name
14911491
}
14921492

1493+
/** Make sure the type parameters of this class are `tparams`, reorder definitions
1494+
* in scope if necessary.
1495+
* @pre All type parameters in `tparams` are entered in class scope `info.decls`.
1496+
*/
1497+
def updateTypeParams(tparams: List[Symbol])(implicit ctx: Context): Unit =
1498+
if (!typeParams.corresponds(tparams)(_.name == _.name)) {
1499+
val decls = info.decls
1500+
val decls1 = newScope
1501+
for (tparam <- tparams) decls1.enter(decls.lookup(tparam.name))
1502+
for (sym <- decls) if (!typeParams.contains(sym)) decls1.enter(sym)
1503+
val ci = classInfo
1504+
// dotty deviation; overloading resolution on next line fails if prefix `ci` is not a value.
1505+
// See test pending/pos/overloaddefault.scala
1506+
info = ci.derivedClassInfo(decls = decls1)
1507+
myTypeParams = null
1508+
}
1509+
14931510
/** All members of this class that have the given name.
14941511
* The elements of the returned pre-denotation all
14951512
* have existing symbols.

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,10 @@ object Scala2Unpickler {
130130
} else {
131131
registerCompanionPair(scalacCompanion, denot.classSymbol)
132132
}
133-
val declsTypeParams = denot.typeParams
134-
val declsInRightOrder =
135-
if (declsTypeParams.corresponds(tparams)(_.name == _.name)) decls
136-
else { // create new scope with type parameters in right order
137-
val decls1 = newScope
138-
for (tparam <- tparams) decls1.enter(decls.lookup(tparam.name))
139-
for (sym <- decls) if (!declsTypeParams.contains(sym)) decls1.enter(sym)
140-
decls1
141-
}
142133

143-
denot.info = ClassInfo( // final info
144-
denot.owner.thisType, denot.classSymbol, parentRefs, declsInRightOrder, ost)
134+
denot.info = ClassInfo( // final info, except possibly for typeparams ordering
135+
denot.owner.thisType, denot.classSymbol, parentRefs, decls, ost)
136+
denot.updateTypeParams(tparams)
145137
}
146138
}
147139

0 commit comments

Comments
 (0)