Skip to content

Commit ce1780f

Browse files
committed
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.
1 parent 6ca52b0 commit ce1780f

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,23 +326,24 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
326326
def ref(tp: NamedType)(implicit ctx: Context): Tree =
327327
if (tp.isType) TypeTree(tp)
328328
else if (prefixIsElidable(tp)) Ident(tp)
329+
else if (tp.symbol.is(Module) && ctx.owner.isContainedIn(tp.symbol.moduleClass))
330+
correctForPath(This(tp.symbol.moduleClass.asClass))
329331
else tp.prefix match {
330-
case pre: SingletonType =>
331-
val prefix =
332-
singleton(pre) match {
333-
case t: This if ctx.erasedTypes && !(t.symbol == ctx.owner.enclosingClass || t.symbol.isStaticOwner) =>
334-
// after erasure outer paths should be respected
335-
new ExplicitOuter.OuterOps(ctx).path(t.tpe.widen.classSymbol)
336-
case t =>
337-
t
338-
}
339-
prefix.select(tp)
332+
case pre: SingletonType => correctForPath(singleton(pre)).select(tp)
340333
case pre => SelectFromTypeTree(TypeTree(pre), tp)
341334
} // no checks necessary
342335

343336
def ref(sym: Symbol)(implicit ctx: Context): Tree =
344337
ref(NamedType(sym.owner.thisType, sym.name, sym.denot))
345338

339+
private def correctForPath(t: Tree)(implicit ctx: Context) = t match {
340+
case t: This if ctx.erasedTypes && !(t.symbol == ctx.owner.enclosingClass || t.symbol.isStaticOwner) =>
341+
// after erasure outer paths should be respected
342+
new ExplicitOuter.OuterOps(ctx).path(t.tpe.widen.classSymbol)
343+
case t =>
344+
t
345+
}
346+
346347
def singleton(tp: Type)(implicit ctx: Context): Tree = tp match {
347348
case tp: TermRef => ref(tp)
348349
case tp: ThisType => This(tp.cls)

src/dotty/tools/dotc/transform/ExplicitOuter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ object ExplicitOuter {
221221
case nw: New =>
222222
isOuter(nw.tpe.classSymbol.owner.enclosingClass)
223223
case _ =>
224-
false
224+
false
225225
}
226226
}
227227

tests/disabled/pos/t3174.scala renamed to tests/pos/t3174.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ object test {
22
def method(): Unit = {
33
class Foo extends AnyRef {
44
object Color {
5-
object Blue
5+
object Blue {
6+
//val b = new Board
7+
}
68
}
79

810
class Board {

0 commit comments

Comments
 (0)