aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-03-12 17:02:47 +0100
committerMartin Odersky <odersky@gmail.com>2014-03-12 17:05:13 +0100
commit66291018e0512b2d4e7d6bac017ab47b95939275 (patch)
tree3ea52f67edcf42c860207ec806d38959654f4f57 /src/dotty/tools/dotc
parent7fa78597bf58a7759303095121a432cb258f447c (diff)
downloaddotty-66291018e0512b2d4e7d6bac017ab47b95939275.tar.gz
dotty-66291018e0512b2d4e7d6bac017ab47b95939275.tar.bz2
dotty-66291018e0512b2d4e7d6bac017ab47b95939275.zip
Fix constructor completion problem detected in t0054
Constructors need to be completed in the context which immediately encloses a class. Otherwise type references in the constructor see the wrong types, as is demonstrated in t0054. The difficulty here is that the inner class B nested in A also extends from A. Then it makes a difference whether the constructor parameter types of B are resolved in the context of B or in the context of A. Added explanation for context handling of constructors.
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala6
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala11
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala6
3 files changed, 16 insertions, 7 deletions
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index bbe5cf986..b92556fa6 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -148,9 +148,9 @@ object SymDenotations {
// completions.println(s"completing ${this.debugString}")
try completer.complete(this)
catch {
- case ex: CyclicReference =>
- completions.println(s"error while completing ${this.debugString}")
- throw ex
+ case ex: CyclicReference =>
+ completions.println(s"error while completing ${this.debugString}")
+ throw ex
}
// completions.println(s"completed ${this.debugString}")
}
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 9c8522b83..2c5022726 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -216,9 +216,18 @@ class Namer { typer: Typer =>
checkNoConflict(name)
val deferred = if (lacksDefinition(tree)) Deferred else EmptyFlags
val method = if (tree.isInstanceOf[DefDef]) Method else EmptyFlags
+
+ // to complete a constructor, move one context further out -- this
+ // is the context enclosing the class. Note that the context in which a
+ // constructor is recorded and the context in which it is completed are
+ // different: The former must have the class as owner (because the
+ // constructor is owned by the class), the latter must not (because
+ // constructor parameters are interpreted as if they are outside the class).
+ val cctx = if (tree.name == nme.CONSTRUCTOR) ctx.outer else ctx
+
record(ctx.newSymbol(
ctx.owner, name, tree.mods.flags | deferred | method,
- adjustIfModule(new Completer(tree), tree),
+ adjustIfModule(new Completer(tree)(cctx), tree),
privateWithinClass(tree.mods), tree.pos))
case tree: Import =>
record(ctx.newSymbol(
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index e195c2807..ef8ce9eed 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -699,9 +699,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val TypeBoundsTree(lo, hi) = desugar.typeBoundsTree(tree)
val lo1 = typed(lo)
val hi1 = typed(hi)
- if (false) // need to do in later phase, as this might cause a cyclic reference error. See pos/t0039.scala
- if (!(lo1.tpe <:< hi1.tpe))
- ctx.error(i"lower bound ${lo1.tpe} does not conform to upper bound ${hi1.tpe}", tree.pos)
+ // need to do in later phase, as this might cause a cyclic reference error. See pos/t0039.scala
+ // if (!(lo1.tpe <:< hi1.tpe))
+ // ctx.error(i"lower bound ${lo1.tpe} does not conform to upper bound ${hi1.tpe}", tree.pos)
assignType(cpy.TypeBoundsTree(tree, lo1, hi1), lo1, hi1)
}