Skip to content

Commit acd41b2

Browse files
committed
Factor out upwardsThisType in RefChecks
We might need it in other places (e.g. self type comparisons).
1 parent de9f642 commit acd41b2

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ object RefChecks {
7373
}
7474
}
7575

76+
/** The this-type of `cls` which should be used when looking at the types of
77+
* inherited members. If `cls` has a non-trivial self type, this returns a skolem
78+
* with the class type instead of the `this-type` of the class as usual.
79+
* This is done because otherwise we want to understand inherited infos
80+
* as they are written, whereas with the this-type they could be
81+
* more special. A test where this makes a difference is pos/i1401.scala.
82+
* This one used to succeed only if forwarding parameters is on.
83+
* (Forwarding tends to hide problems by binding parameter names).
84+
*/
85+
private def upwardsThisType(cls: Symbol)(implicit ctx: Context) = cls.info match {
86+
case ClassInfo(_, _, _, _, tp: Type) if (tp ne cls.typeRef) && !cls.is(ModuleOrFinal) =>
87+
SkolemType(cls.typeRef).withName(nme.this_)
88+
case _ =>
89+
cls.thisType
90+
}
91+
7692
/** Check that self type of this class conforms to self types of parents.
7793
* and required classes.
7894
*/
@@ -134,20 +150,7 @@ object RefChecks {
134150
* before, but it looks too complicated and method bodies are far too large.
135151
*/
136152
private def checkAllOverrides(clazz: Symbol)(implicit ctx: Context): Unit = {
137-
val self = clazz.info match {
138-
case ClassInfo(_, _, _, _, tp: Type)
139-
if (tp ne clazz.typeRef) && !clazz.is(ModuleOrFinal) =>
140-
// If class has a non-trivial self type, use a skolem with the class type
141-
// as `self` reference, instead of the `this-type` of the class as usual.
142-
// This is done because otherwise we want to understand inherited infos
143-
// as they are written, whereas with the this-type they could be
144-
// more special. A test where this makes a difference is pos/i1401.scala.
145-
// This one used to succeed only if forwarding parameters is on.
146-
// (Forwarding tends to hide problems by binding parameter names).
147-
SkolemType(clazz.typeRef).withName(nme.this_)
148-
case _ =>
149-
clazz.thisType
150-
}
153+
val self = upwardsThisType(clazz)
151154
var hasErrors = false
152155

153156
case class MixinOverrideError(member: Symbol, msg: String)

0 commit comments

Comments
 (0)