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 all 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))
followOuterLinks(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 => followOuterLinks(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 followOuterLinks(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)
Expand Down
27 changes: 10 additions & 17 deletions src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -274,24 +274,17 @@ object Denotations {
val sym1 = denot1.symbol
val sym2 = denot2.symbol
val sym2Accessible = sym2.isAccessibleFrom(pre)
def shadows(sym1: Symbol, sym2: Symbol) = {
val owner1 = sym1.owner
val owner2 = sym2.owner
owner1.derivesFrom(owner2) && owner1.ne(owner2)
def unshadowed(sym: Symbol, from: Symbol) = {
val symOwner = sym.owner
val fromOwner = from.owner
!fromOwner.derivesFrom(symOwner) || fromOwner.eq(symOwner)
}
/** Preference according to order (overrides, isAsConcrete, shadows)*/
/** Preference according to partial pre-order (isConcrete, unshadowed) */
def preferSym(sym1: Symbol, sym2: Symbol) =
sym1.isAsConcrete(sym2) && (!sym2.isAsConcrete(sym1) || unshadowed(sym1, sym2))
/** Sym preference provided types also override */
def prefer(info1: Type, sym1: Symbol, info2: Type, sym2: Symbol) =
info1.overrides(info2) && (
// non-standard ordering of tests for efficiency -
// overrides is costlier to compute than the others, so its 2nd test comes last.
sym1.isAsConcrete(sym2) && (
!sym2.isAsConcrete(sym1)
||
shadows(sym1, sym2)
)
||
!info2.overrides(info1)
)
preferSym(sym1, sym2) && info1.overrides(info2)
if (sym2Accessible && prefer(info2, sym2, info1, sym1)) denot2
else {
val sym1Accessible = sym1.isAccessibleFrom(pre)
Expand All @@ -302,7 +295,7 @@ object Denotations {
val sym =
if (!sym1.exists) sym2
else if (!sym2.exists) sym1
else if (sym2 isAsConcrete sym1) sym2
else if (preferSym(sym2, sym1)) sym2
else sym1
new JointRefDenotation(sym, info1 & info2, denot1.validFor & denot2.validFor)
}
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
15 changes: 8 additions & 7 deletions src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ object RefChecks {
for (member <- missing) {
val memberSym = member.symbol
def undefined(msg: String) =
abstractClassError(false, member.showDcl + " is not defined" + msg)
abstractClassError(false, s"${member.showDcl} is not defined $msg")
val underlying = memberSym.underlyingSymbol

// Give a specific error message for abstract vars based on why it fails:
Expand Down Expand Up @@ -456,9 +456,8 @@ object RefChecks {
case (pa, pc) :: Nil =>
val abstractSym = pa.typeSymbol
val concreteSym = pc.typeSymbol
def subclassMsg(c1: Symbol, c2: Symbol) = (
": %s is a subclass of %s, but method parameter types must match exactly.".format(
c1.showLocated, c2.showLocated))
def subclassMsg(c1: Symbol, c2: Symbol) =
s": ${c1.showLocated} is a subclass of ${c2.showLocated}, but method parameter types must match exactly."
val addendum =
if (abstractSym == concreteSym) {
val paArgs = pa.argInfos
Expand All @@ -478,12 +477,14 @@ object RefChecks {
subclassMsg(concreteSym, abstractSym)
else ""

undefined("\n(Note that %s does not match %s%s)".format(pa, pc, addendum))
undefined(s"\n(Note that $pa does not match $pc$addendum)")
case xs =>
undefined("")
undefined(s"\n(The class implements a member with a different type: ${concrete.showDcl})")
}
case _ =>
case Nil =>
undefined("")
case concretes =>
undefined(s"\n(The class implements members with different types: ${concretes.map(_.showDcl)}%\n %)")
}
} else undefined("")
}
Expand Down
File renamed without changes.
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
File renamed without changes.