Skip to content

Commit ef6922c

Browse files
committed
Factor out upwardsThisType in RefChecks
We might need it in other places (e.g. self type comparisons). # Conflicts: # compiler/src/dotty/tools/dotc/typer/RefChecks.scala
1 parent d92f456 commit ef6922c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
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,7 +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.thisType
153+
val self = upwardsThisType(clazz)
138154
var hasErrors = false
139155

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

0 commit comments

Comments
 (0)