Skip to content

Fix #2858: Handle intersection selection when symbol only exists on one side #2861

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 1 commit into from
Jul 13, 2017
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
29 changes: 15 additions & 14 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -386,25 +386,28 @@ object Denotations {
/** Establish a partial order "preference" order between symbols.
* Give preference to `sym1` over `sym2` if one of the following
* conditions holds, in decreasing order of weight:
* 1. sym1 is concrete and sym2 is abstract
* 2. The owner of sym1 comes before the owner of sym2 in the linearization
* 1. sym2 doesn't exist
* 2. sym1 is concrete and sym2 is abstract
* 3. The owner of sym1 comes before the owner of sym2 in the linearization
* of the type of the prefix `pre`.
* 3. The access boundary of sym2 is properly contained in the access
* 4. The access boundary of sym2 is properly contained in the access
* boundary of sym1. For protected access, we count the enclosing
* package as access boundary.
* 4. sym1 a method but sym2 is not.
* 5. sym1 a method but sym2 is not.
* The aim of these criteria is to give some disambiguation on access which
* - does not depend on textual order or other arbitrary choices
* - minimizes raising of doubleDef errors
*/
def preferSym(sym1: Symbol, sym2: Symbol) =
sym1.eq(sym2) ||
sym1.isAsConcrete(sym2) &&
(!sym2.isAsConcrete(sym1) ||
precedes(sym1.owner, sym2.owner) ||
accessBoundary(sym2).isProperlyContainedIn(accessBoundary(sym1)) ||
sym1.is(Method) && !sym2.is(Method)) ||
sym1.info.isErroneous
sym1.exists &&
(!sym2.exists ||
sym1.isAsConcrete(sym2) &&
(!sym2.isAsConcrete(sym1) ||
precedes(sym1.owner, sym2.owner) ||
accessBoundary(sym2).isProperlyContainedIn(accessBoundary(sym1)) ||
sym1.is(Method) && !sym2.is(Method)) ||
sym1.info.isErroneous)

/** Sym preference provided types also override */
def prefer(sym1: Symbol, sym2: Symbol, info1: Type, info2: Type) =
Expand All @@ -425,9 +428,7 @@ object Denotations {
else if (isDoubleDef(sym1, sym2)) handleDoubleDef
else {
val sym =
if (!sym1.exists) sym2
else if (!sym2.exists) sym1
else if (preferSym(sym2, sym1)) sym2
if (preferSym(sym2, sym1)) sym2
else sym1
val jointInfo =
try infoMeet(info1, info2)
Expand Down Expand Up @@ -1243,4 +1244,4 @@ object Denotations {
util.Stats.record("stale symbol")
override def getMessage() = msg
}
}
}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ object SymDenotations {
sym.owner == defn.AnyClass ||
sym == defn.Object_clone ||
sym.owner.is(Scala2x)
test(symbol) || allOverriddenSymbols.exists(test)
this.exists && (test(symbol) || allOverriddenSymbols.exists(test))
}

// ------ access to related symbols ---------------------------------
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i2858.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Cont[A0](x0: A0) { type A = A0; val x: A = x0 }

object Test {
def test: Unit = {
val c: Cont[_] & { type A = Int } = new Cont(1)
c.x
}
}