aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-06-07 16:45:50 +0200
committerMartin Odersky <odersky@gmail.com>2015-06-07 16:46:05 +0200
commitce1780fbcbafd7be298f930a611743386aa0d6a6 (patch)
tree7a4c21d33746a2f5f3f993dbe7d02382b276324b
parent6ca52b0f23f0c3425d054d0918a149e0e7afb765 (diff)
downloaddotty-ce1780fbcbafd7be298f930a611743386aa0d6a6.tar.gz
dotty-ce1780fbcbafd7be298f930a611743386aa0d6a6.tar.bz2
dotty-ce1780fbcbafd7be298f930a611743386aa0d6a6.zip
Fix refs to inner objects
A reference to an object from anywhere in its module class can be established by the This of the module class. The previous behavior always referenced the object as a term ref which might cause a reference to the outer This which might not be available (since this is not tracked by ExplicitOuter). Brings t3174.scala back from disabled.
-rw-r--r--src/dotty/tools/dotc/ast/tpd.scala21
-rw-r--r--src/dotty/tools/dotc/transform/ExplicitOuter.scala2
-rw-r--r--tests/pos/t3174.scala (renamed from tests/disabled/pos/t3174.scala)4
3 files changed, 15 insertions, 12 deletions
diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala
index e38de458a..d0a7942c5 100644
--- a/src/dotty/tools/dotc/ast/tpd.scala
+++ b/src/dotty/tools/dotc/ast/tpd.scala
@@ -326,23 +326,24 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def ref(tp: NamedType)(implicit ctx: Context): Tree =
if (tp.isType) TypeTree(tp)
else if (prefixIsElidable(tp)) Ident(tp)
+ else if (tp.symbol.is(Module) && ctx.owner.isContainedIn(tp.symbol.moduleClass))
+ correctForPath(This(tp.symbol.moduleClass.asClass))
else tp.prefix match {
- case pre: SingletonType =>
- val prefix =
- singleton(pre) match {
- case t: This if ctx.erasedTypes && !(t.symbol == ctx.owner.enclosingClass || t.symbol.isStaticOwner) =>
- // after erasure outer paths should be respected
- new ExplicitOuter.OuterOps(ctx).path(t.tpe.widen.classSymbol)
- case t =>
- t
- }
- prefix.select(tp)
+ case pre: SingletonType => correctForPath(singleton(pre)).select(tp)
case pre => SelectFromTypeTree(TypeTree(pre), tp)
} // no checks necessary
def ref(sym: Symbol)(implicit ctx: Context): Tree =
ref(NamedType(sym.owner.thisType, sym.name, sym.denot))
+ private def correctForPath(t: Tree)(implicit ctx: Context) = t match {
+ case t: This if ctx.erasedTypes && !(t.symbol == ctx.owner.enclosingClass || t.symbol.isStaticOwner) =>
+ // after erasure outer paths should be respected
+ new ExplicitOuter.OuterOps(ctx).path(t.tpe.widen.classSymbol)
+ case t =>
+ t
+ }
+
def singleton(tp: Type)(implicit ctx: Context): Tree = tp match {
case tp: TermRef => ref(tp)
case tp: ThisType => This(tp.cls)
diff --git a/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/src/dotty/tools/dotc/transform/ExplicitOuter.scala
index 0fa429d6e..912bc9b7f 100644
--- a/src/dotty/tools/dotc/transform/ExplicitOuter.scala
+++ b/src/dotty/tools/dotc/transform/ExplicitOuter.scala
@@ -221,7 +221,7 @@ object ExplicitOuter {
case nw: New =>
isOuter(nw.tpe.classSymbol.owner.enclosingClass)
case _ =>
- false
+ false
}
}
diff --git a/tests/disabled/pos/t3174.scala b/tests/pos/t3174.scala
index 8d9b2578d..bae941bc1 100644
--- a/tests/disabled/pos/t3174.scala
+++ b/tests/pos/t3174.scala
@@ -2,7 +2,9 @@ object test {
def method(): Unit = {
class Foo extends AnyRef {
object Color {
- object Blue
+ object Blue {
+ //val b = new Board
+ }
}
class Board {