aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/typer/Mode.scala3
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala4
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala16
3 files changed, 17 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/typer/Mode.scala b/src/dotty/tools/dotc/typer/Mode.scala
index 65afbd7c8..55baa6bc5 100644
--- a/src/dotty/tools/dotc/typer/Mode.scala
+++ b/src/dotty/tools/dotc/typer/Mode.scala
@@ -29,9 +29,10 @@ object Mode {
val Type = newMode(1, "Type")
val ImplicitsEnabled = newMode(2, "ImplicitsEnabled")
- val InferringReturnType = newMode(3, "InferencingReturnType")
+ val InferringReturnType = newMode(3, "InferringReturnType")
val TypevarsMissContext = newMode(4, "TypevarsMissContext")
+ val InSuperCall = newMode(5, "InSuperCall")
val PatternOrType = Pattern | Type
} \ No newline at end of file
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index c0e39c44c..d10ac9fb2 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -372,7 +372,7 @@ class Namer { typer: Typer =>
/** The type of a parent constructor. Types constructor arguments
* only if parent type contains uninstantiated type parameters.
*/
- def parentType(constr: untpd.Tree): Type =
+ def parentType(constr: untpd.Tree)(implicit ctx: Context): Type =
if (constr.isType) { // this case applies to desugared refined types
typedAheadType(constr).tpe
} else {
@@ -393,7 +393,7 @@ class Namer { typer: Typer =>
else createSymbol(self)
// pre-set info, so that parent types can refer to type params
denot.info = ClassInfo(cls.owner.thisType, cls, Nil, decls, selfInfo)
- val parentTypes = parents map parentType
+ val parentTypes = parents map (parentType(_)(ctx.fresh addMode Mode.InSuperCall))
val parentRefs = ctx.normalizeToClassRefs(parentTypes, cls, decls)
val parentClsRefs =
for ((parentRef, constr) <- parentRefs zip parents)
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 9931e3a2e..a40062127 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -141,11 +141,20 @@ class Typer extends Namer with Applications with Implicits {
tpe
}
+ /** The enclosing class, except if we are in a super call, in which case
+ * it is the next outer one.
+ */
+ def effectiveEnclosingClass(implicit ctx: Context) = {
+ val enclClass = ctx.owner.enclosingClass
+ if ((ctx.mode is Mode.InSuperCall) && enclClass.exists) enclClass.owner.enclosingClass
+ else enclClass
+ }
+
/** The qualifying class of a this or super with prefix `qual` (which might be empty).
* @param packageOk The qualifier may refer to a package.
*/
- def qualifyingClass(tree: untpd.Tree, qual: Name, packageOK: Boolean)(implicit ctx: Context): Symbol =
- ctx.owner.enclosingClass.ownersIterator.find(o => qual.isEmpty || o.isClass && o.name == qual) match {
+ def qualifyingClass(tree: untpd.Tree, qual: Name, packageOK: Boolean)(implicit ctx: Context): Symbol = {
+ effectiveEnclosingClass.ownersIterator.find(o => qual.isEmpty || o.isClass && o.name == qual) match {
case Some(c) if packageOK || !(c is Package) =>
c
case _ =>
@@ -154,6 +163,7 @@ class Typer extends Namer with Applications with Implicits {
else qual.show + " is not an enclosing class", tree.pos)
NoSymbol
}
+ }
/** Attribute an identifier consisting of a simple name or wildcard
*
@@ -858,7 +868,7 @@ class Typer extends Namer with Applications with Implicits {
val TypeDef(mods, name, impl @ Template(constr, parents, self, body)) = cdef
val mods1 = typedModifiers(mods)
val constr1 = typed(constr).asInstanceOf[DefDef]
- val parents1 = parents mapconserve (typed(_))
+ val parents1 = parents mapconserve (typed(_)(ctx.fresh addMode Mode.InSuperCall))
val self1 = typed(self).asInstanceOf[ValDef]
val localDummy = ctx.newLocalDummy(cls, impl.pos)
val body1 = typedStats(body, localDummy)(inClassContext(self1.symbol))