Skip to content

Fix/refs to inner objects #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 7, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does For in the name stand for?
As this method is used only in ref and is private anyway, maybe it's better to move its definition to ref and give it a proper name, eg followOuterLinks?

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)
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/transform/ExplicitOuter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ object ExplicitOuter {
case nw: New =>
isOuter(nw.tpe.classSymbol.owner.enclosingClass)
case _ =>
false
false
}
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion tests/disabled/pos/t3174.scala → tests/pos/t3174.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down