@@ -366,29 +366,32 @@ object Denotations {
366
366
*
367
367
* NoDenotations are dropped. MultiDenotations are handled by merging
368
368
* parts with same signatures. SingleDenotations with equal signatures
369
- * are joined as follows :
369
+ * are joined by following this sequence of steps :
370
370
*
371
- * In a first step, consider only those denotations which have symbols
372
- * that are accessible from prefix `pre`.
371
+ * 1. If exactly one the denotations has an inaccessible symbol, pick the other one.
372
+ * 2. Otherwise, if one of the infos overrides the other one, and the associated
373
+ * symbol does not score strictly lower than the other one,
374
+ * pick the associated denotation.
375
+ * 3. Otherwise, if the two infos can be combined with `infoMeet`, pick that as
376
+ * result info, and pick the symbol that scores higher as result symbol,
377
+ * or pick `sym2` as a tie breaker. The picked info and symbol are combined
378
+ * in a JointDenotation.
379
+ * 4. Otherwise, if one of the two symbols scores strongly higher than the
380
+ * other one, pick the associated denotation.
381
+ * 5. Otherwise return a multi-denotation consisting of both denotations.
373
382
*
374
- * If there are several such denotations, try to pick one by applying the following
375
- * three precedence rules in decreasing order of priority:
383
+ * Symbol scoring is determined according to the following ranking
384
+ * where earlier criteria trump later ones. Cases marked with (*)
385
+ * give a strong score advantage, the others a weak one.
376
386
*
377
- * 1. Prefer denotations with more specific infos.
378
- * 2. If infos are equally specific, prefer denotations with concrete symbols over denotations
379
- * with abstract symbols.
380
- * 3. If infos are equally specific and symbols are equally concrete,
381
- * prefer denotations with symbols defined in subclasses
382
- * over denotations with symbols defined in proper superclasses.
383
- *
384
- * If there is exactly one (preferred) accessible denotation, return it.
385
- *
386
- * If there is no preferred accessible denotation, return a JointRefDenotation
387
- * with one of the operand symbols (unspecified which one), and an info which
388
- * is the intersection using `&` or `safe_&` if `safeIntersection` is true)
389
- * of the infos of the operand denotations.
387
+ * 1. The symbol exists, and the other one does not. (*)
388
+ * 2. The symbol is concrete, and the other one is deferred
389
+ * 3. The symbol appears before the other in the linearization of `pre`
390
+ * 4. The symbol's visibility is strictly greater than the other one's.
391
+ * 5. The symbol is not a bridge, but the other one is. (*)
392
+ * 6. The symbol is a method, but the other one is not. (*)
390
393
*/
391
- def & (that : Denotation , pre : Type , safeIntersection : Boolean = false )(implicit ctx : Context ): Denotation = {
394
+ def meet (that : Denotation , pre : Type , safeIntersection : Boolean = false )(implicit ctx : Context ): Denotation = {
392
395
/** Try to merge denot1 and denot2 without adding a new signature. */
393
396
def mergeDenot (denot1 : Denotation , denot2 : SingleDenotation ): Denotation = denot1 match {
394
397
case denot1 @ MultiDenotation (denot11, denot12) =>
@@ -412,7 +415,7 @@ object Denotations {
412
415
val sym1 = denot1.symbol
413
416
val sym2 = denot2.symbol
414
417
415
- /** Does `sym1 ` come before `sym2 ` in the linearization of `pre`? */
418
+ /** Does `owner1 ` come before `owner2 ` in the linearization of `pre`? */
416
419
def linearScore (owner1 : Symbol , owner2 : Symbol ): Int =
417
420
418
421
def searchBaseClasses (bcs : List [ClassSymbol ]): Int = bcs match
@@ -441,6 +444,10 @@ object Denotations {
441
444
if hidden1 && ! hidden2 then denot2
442
445
else if hidden2 && ! hidden1 then denot1
443
446
else
447
+ // The score that determines which symbol to pick for the result denotation.
448
+ // A value > 0 means pick `sym1`, < 0 means pick `sym2`.
449
+ // A value of +/- 2 means pick one of the denotations as a tie-breaker
450
+ // if a common info does not exist.
444
451
val symScore : Int =
445
452
if ! sym1.exists then - 2
446
453
else if ! sym2.exists then 2
@@ -488,7 +495,7 @@ object Denotations {
488
495
val r = mergeDenot(this , that)
489
496
if (r.exists) r else MultiDenotation (this , that)
490
497
case that @ MultiDenotation (denot1, denot2) =>
491
- this & (denot1, pre) & (denot2, pre)
498
+ this .meet (denot1, pre).meet (denot2, pre)
492
499
}
493
500
}
494
501
@@ -1106,7 +1113,7 @@ object Denotations {
1106
1113
final case class DenotUnion (denot1 : PreDenotation , denot2 : PreDenotation ) extends MultiPreDenotation {
1107
1114
def exists : Boolean = true
1108
1115
def toDenot (pre : Type )(implicit ctx : Context ): Denotation =
1109
- denot1.toDenot(pre).& (denot2.toDenot(pre), pre)
1116
+ denot1.toDenot(pre).meet (denot2.toDenot(pre), pre)
1110
1117
def containsSym (sym : Symbol ): Boolean =
1111
1118
(denot1 containsSym sym) || (denot2 containsSym sym)
1112
1119
type AsSeenFromResult = PreDenotation
0 commit comments