aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Denotations.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-07-15 13:06:22 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-15 13:08:59 +0200
commitb93ffa5cc46533cb8a74d19fbc46e0287cedecdd (patch)
tree0d8466c7b7c85c25be252535af84e62e86e4ba58 /src/dotty/tools/dotc/core/Denotations.scala
parent4bec4fa6d6c1844abab4e4e64ea7763e17ca30bf (diff)
downloaddotty-b93ffa5cc46533cb8a74d19fbc46e0287cedecdd.tar.gz
dotty-b93ffa5cc46533cb8a74d19fbc46e0287cedecdd.tar.bz2
dotty-b93ffa5cc46533cb8a74d19fbc46e0287cedecdd.zip
Fix #1386: Reduce double def errors
Use additional disambiguation criteria before raising a double def error. See for context: #1240. Review by @darkdimius
Diffstat (limited to 'src/dotty/tools/dotc/core/Denotations.scala')
-rw-r--r--src/dotty/tools/dotc/core/Denotations.scala30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala
index 5ce8cbcd8..e23e66b95 100644
--- a/src/dotty/tools/dotc/core/Denotations.scala
+++ b/src/dotty/tools/dotc/core/Denotations.scala
@@ -292,24 +292,41 @@ object Denotations {
val sym1 = denot1.symbol
val sym2 = denot2.symbol
- if (isDoubleDef(sym1, sym2)) doubleDefError(denot1, denot2, pre)
-
val sym2Accessible = sym2.isAccessibleFrom(pre)
+
/** Does `sym1` come before `sym2` in the linearization of `pre`? */
def precedes(sym1: Symbol, sym2: Symbol) = {
def precedesIn(bcs: List[ClassSymbol]): Boolean = bcs match {
case bc :: bcs1 => (sym1 eq bc) || !(sym2 eq bc) && precedesIn(bcs1)
case Nil => true
}
- sym1.derivesFrom(sym2) ||
- !sym2.derivesFrom(sym1) && precedesIn(pre.baseClasses)
+ (sym1 ne sym2) &&
+ (sym1.derivesFrom(sym2) ||
+ !sym2.derivesFrom(sym1) && precedesIn(pre.baseClasses))
}
- /** Preference according to partial pre-order (isConcrete, precedes) */
+ /** 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
+ * of the type of the prefix `pre`.
+ * 3. 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.
+ * 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))
+ (!sym2.isAsConcrete(sym1) ||
+ precedes(sym1.owner, sym2.owner) ||
+ sym2.accessBoundary(sym2.enclosingPackageClass)
+ .isProperlyContainedIn(sym1.accessBoundary(sym1.enclosingPackageClass)) ||
+ sym1.is(Method) && !sym2.is(Method))
/** Sym preference provided types also override */
def prefer(sym1: Symbol, sym2: Symbol, info1: Type, info2: Type) =
@@ -321,6 +338,7 @@ object Denotations {
if (sym1Accessible && prefer(sym1, sym2, info1, info2)) denot1
else if (sym1Accessible && sym2.exists && !sym2Accessible) denot1
else if (sym2Accessible && sym1.exists && !sym1Accessible) denot2
+ else if (isDoubleDef(sym1, sym2)) doubleDefError(denot1, denot2, pre)
else {
val sym =
if (!sym1.exists) sym2