@@ -122,11 +122,11 @@ object Denotations {
122
122
/** The signature of the denotation. */
123
123
def signature (implicit ctx : Context ): Signature
124
124
125
- /** Resolve overloaded denotation to pick the one with the given signature
125
+ /** Resolve overloaded denotation to pick the ones with the given signature
126
126
* when seen from prefix `site`.
127
127
* @param relaxed When true, consider only parameter signatures for a match.
128
128
*/
129
- def atSignature (sig : Signature , site : Type = NoPrefix , relaxed : Boolean = false )(implicit ctx : Context ): SingleDenotation
129
+ def atSignature (sig : Signature , site : Type = NoPrefix , relaxed : Boolean = false )(implicit ctx : Context ): Denotation
130
130
131
131
/** The variant of this denotation that's current in the given context, or
132
132
* `NotDefinedHereDenotation` if this denotation does not exist at current phase, but
@@ -157,7 +157,10 @@ object Denotations {
157
157
* or NoDenotation if no satisfying alternative exists.
158
158
* @throws TypeError if there is at more than one alternative that satisfies `p`.
159
159
*/
160
- def suchThat (p : Symbol => Boolean ): SingleDenotation
160
+ def suchThat (p : Symbol => Boolean )(implicit ctx : Context ): SingleDenotation
161
+
162
+ /** If this is a SingleDenotation, return it, otherwise throw a TypeError */
163
+ def checkUnique (implicit ctx : Context ): SingleDenotation = suchThat(alwaysTrue)
161
164
162
165
/** Does this denotation have an alternative that satisfies the predicate `p`? */
163
166
def hasAltWith (p : SingleDenotation => Boolean ): Boolean
@@ -227,13 +230,17 @@ object Denotations {
227
230
/** The alternative of this denotation that has a type matching `targetType` when seen
228
231
* as a member of type `site`, `NoDenotation` if none exists.
229
232
*/
230
- def matchingDenotation (site : Type , targetType : Type )(implicit ctx : Context ): SingleDenotation =
231
- if (isOverloaded)
232
- atSignature(targetType.signature, site, relaxed = true ).matchingDenotation(site, targetType)
233
- else if (exists && ! site.memberInfo(symbol).matchesLoosely(targetType))
234
- NoDenotation
235
- else
236
- asSingleDenotation
233
+ def matchingDenotation (site : Type , targetType : Type )(implicit ctx : Context ): SingleDenotation = {
234
+ def qualifies (sym : Symbol ) = site.memberInfo(sym).matchesLoosely(targetType)
235
+ if (isOverloaded) {
236
+ atSignature(targetType.signature, site, relaxed = true ) match {
237
+ case sd : SingleDenotation => sd.matchingDenotation(site, targetType)
238
+ case md => md.suchThat(qualifies(_))
239
+ }
240
+ }
241
+ else if (exists && ! qualifies(symbol)) NoDenotation
242
+ else asSingleDenotation
243
+ }
237
244
238
245
/** Form a denotation by conjoining with denotation `that`.
239
246
*
@@ -420,23 +427,21 @@ object Denotations {
420
427
final def validFor = denot1.validFor & denot2.validFor
421
428
final def isType = false
422
429
final def signature (implicit ctx : Context ) = Signature .OverloadedSignature
423
- def atSignature (sig : Signature , site : Type , relaxed : Boolean )(implicit ctx : Context ): SingleDenotation = {
424
- val atSig1 = denot1.atSignature(sig, site, relaxed)
425
- val atSig2 = denot2.atSignature(sig, site, relaxed)
426
- if (isDoubleDef(atSig1.symbol, atSig2.symbol)) doubleDefError(atSig1, atSig2, site)
427
- atSig1.orElse(atSig2)
428
- }
430
+ def atSignature (sig : Signature , site : Type , relaxed : Boolean )(implicit ctx : Context ): Denotation =
431
+ derivedMultiDenotation(denot1.atSignature(sig, site, relaxed), denot2.atSignature(sig, site, relaxed))
429
432
def currentIfExists (implicit ctx : Context ): Denotation =
430
433
derivedMultiDenotation(denot1.currentIfExists, denot2.currentIfExists)
431
434
def current (implicit ctx : Context ): Denotation =
432
435
derivedMultiDenotation(denot1.current, denot2.current)
433
436
def altsWith (p : Symbol => Boolean ): List [SingleDenotation ] =
434
437
denot1.altsWith(p) ++ denot2.altsWith(p)
435
- def suchThat (p : Symbol => Boolean ): SingleDenotation = {
438
+ def suchThat (p : Symbol => Boolean )( implicit ctx : Context ) : SingleDenotation = {
436
439
val sd1 = denot1.suchThat(p)
437
440
val sd2 = denot2.suchThat(p)
438
441
if (sd1.exists)
439
- if (sd2.exists) throw new TypeError (s " failure to disambiguate overloaded reference $this" )
442
+ if (sd2.exists)
443
+ if (isDoubleDef(denot1.symbol, denot2.symbol)) doubleDefError(denot1, denot2)
444
+ else throw new TypeError (s " failure to disambiguate overloaded reference $this" )
440
445
else sd1
441
446
else sd2
442
447
}
@@ -486,7 +491,7 @@ object Denotations {
486
491
def altsWith (p : Symbol => Boolean ): List [SingleDenotation ] =
487
492
if (exists && p(symbol)) this :: Nil else Nil
488
493
489
- def suchThat (p : Symbol => Boolean ): SingleDenotation =
494
+ def suchThat (p : Symbol => Boolean )( implicit ctx : Context ) : SingleDenotation =
490
495
if (exists && p(symbol)) this else NoDenotation
491
496
492
497
def hasAltWith (p : SingleDenotation => Boolean ): Boolean =
@@ -906,14 +911,14 @@ object Denotations {
906
911
*/
907
912
case class NoQualifyingRef (alts : List [SingleDenotation ])(implicit ctx : Context ) extends ErrorDenotation
908
913
909
- /** A double defifinition
914
+ /** A double definition
910
915
*/
911
916
def isDoubleDef (sym1 : Symbol , sym2 : Symbol )(implicit ctx : Context ): Boolean =
912
917
(sym1.exists && sym2.exists &&
913
918
(sym1 ne sym2) && (sym1.owner eq sym2.owner) &&
914
919
! sym1.is(Bridge ) && ! sym2.is(Bridge ))
915
920
916
- def doubleDefError (denot1 : SingleDenotation , denot2 : SingleDenotation , pre : Type )(implicit ctx : Context ): Unit = {
921
+ def doubleDefError (denot1 : Denotation , denot2 : Denotation , pre : Type = NoPrefix )(implicit ctx : Context ): Nothing = {
917
922
val sym1 = denot1.symbol
918
923
val sym2 = denot2.symbol
919
924
def fromWhere = if (pre == NoPrefix ) " " else i " \n when seen as members of $pre"
@@ -927,7 +932,6 @@ object Denotations {
927
932
denot2.info, denot2.info)
928
933
}
929
934
930
-
931
935
// --------------- PreDenotations -------------------------------------------------
932
936
933
937
/** A PreDenotation represents a group of single denotations
0 commit comments