aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/TypeOps.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-07-21 14:51:16 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-21 17:42:53 +0200
commitc37185d3307e2b02e25e888fd44d5e8bba95aa1d (patch)
treeb0ec5f8198a559abb1cf83f68a8bed3ad318a4a4 /src/dotty/tools/dotc/core/TypeOps.scala
parenteaffc785be1e42c3a44ce149dfb8cabb6681d7c6 (diff)
downloaddotty-c37185d3307e2b02e25e888fd44d5e8bba95aa1d.tar.gz
dotty-c37185d3307e2b02e25e888fd44d5e8bba95aa1d.tar.bz2
dotty-c37185d3307e2b02e25e888fd44d5e8bba95aa1d.zip
Fix #1401: Make sure all refs are forwarded
Faced with recursive dependencies through self types, we might have to apply `normalizeToClassRefs` to a class P with a parent that is not yet initialized (witnessed by P's parents being Nil). In that case we should still execute forwardRefs on P, but we have to wait in a suspension until P is initialized. This avoids the problem raised in #1401. I am still not quite sure why forwardRefs is needed, but it seems that asSeenFrom alone is not enough to track the dependencies in this case.
Diffstat (limited to 'src/dotty/tools/dotc/core/TypeOps.scala')
-rw-r--r--src/dotty/tools/dotc/core/TypeOps.scala22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala
index 10b0f5615..9433cb882 100644
--- a/src/dotty/tools/dotc/core/TypeOps.scala
+++ b/src/dotty/tools/dotc/core/TypeOps.scala
@@ -361,13 +361,23 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
* to the current scope, provided (1) variances of both aliases are the same, and
* (2) X is not yet defined in current scope. This "short-circuiting" prevents
* long chains of aliases which would have to be traversed in type comparers.
+ *
+ * Note: Test i1401.scala shows that `forwardRefs` is also necessary
+ * for typechecking in the case where self types refer to type parameters
+ * that are upper-bounded by subclass instances.
*/
def forwardRefs(from: Symbol, to: Type, prefs: List[TypeRef]) = to match {
case to @ TypeBounds(lo1, hi1) if lo1 eq hi1 =>
- for (pref <- prefs)
- for (argSym <- pref.decls)
- if (argSym is BaseTypeArg)
- forwardRef(argSym, from, to, cls, decls)
+ for (pref <- prefs) {
+ def forward(): Unit =
+ for (argSym <- pref.decls)
+ if (argSym is BaseTypeArg)
+ forwardRef(argSym, from, to, cls, decls)
+ pref.info match {
+ case info: TempClassInfo => info.suspensions = (() => forward()) :: info.suspensions // !!! dotty deviation `forward` alone does not eta expand
+ case _ => forward()
+ }
+ }
case _ =>
}
@@ -419,9 +429,9 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
s"redefinition of ${decls.lookup(name).debugString} in ${cls.showLocated}")
enterArgBinding(formals(name), refinedInfo, cls, decls)
}
- // Forward definitions in super classes that have one of the refined paramters
+ // Forward definitions in super classes that have one of the refined parameters
// as aliases directly to the refined info.
- // Note that this cannot be fused bwith the previous loop because we now
+ // Note that this cannot be fused with the previous loop because we now
// assume that all arguments have been entered in `decls`.
refinements foreachBinding { (name, refinedInfo) =>
forwardRefs(formals(name), refinedInfo, parentRefs)