Skip to content

Commit 4544099

Browse files
committed
Refine atSignature
atSignature should also check result type names, except - if one of the result is a wildcard - a boolean flag relaxed is explicitly set
1 parent 5d3b786 commit 4544099

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ object Denotations {
125125

126126
/** Resolve overloaded denotation to pick the one with the given signature
127127
* when seen from prefix `site`.
128+
* @param relaxed When true, consider only parameter signatures for a match.
128129
*/
129-
def atSignature(sig: Signature, site: Type = NoPrefix)(implicit ctx: Context): SingleDenotation
130+
def atSignature(sig: Signature, site: Type = NoPrefix, relaxed: Boolean = false)(implicit ctx: Context): SingleDenotation
130131

131132
/** The variant of this denotation that's current in the given context, or
132133
* `NotDefinedHereDenotation` if this denotation does not exist at current phase, but
@@ -221,7 +222,7 @@ object Denotations {
221222
*/
222223
def matchingDenotation(site: Type, targetType: Type)(implicit ctx: Context): SingleDenotation =
223224
if (isOverloaded)
224-
atSignature(targetType.signature, site).matchingDenotation(site, targetType)
225+
atSignature(targetType.signature, site, relaxed = true).matchingDenotation(site, targetType)
225226
else if (exists && !site.memberInfo(symbol).matchesLoosely(targetType))
226227
NoDenotation
227228
else
@@ -398,8 +399,8 @@ object Denotations {
398399
final def validFor = denot1.validFor & denot2.validFor
399400
final def isType = false
400401
final def signature(implicit ctx: Context) = Signature.OverloadedSignature
401-
def atSignature(sig: Signature, site: Type)(implicit ctx: Context): SingleDenotation =
402-
denot1.atSignature(sig, site) orElse denot2.atSignature(sig, site)
402+
def atSignature(sig: Signature, site: Type, relaxed: Boolean)(implicit ctx: Context): SingleDenotation =
403+
denot1.atSignature(sig, site, relaxed) orElse denot2.atSignature(sig, site, relaxed)
403404
def currentIfExists(implicit ctx: Context): Denotation =
404405
derivedMultiDenotation(denot1.currentIfExists, denot2.currentIfExists)
405406
def current(implicit ctx: Context): Denotation =
@@ -469,9 +470,12 @@ object Denotations {
469470
def accessibleFrom(pre: Type, superAccess: Boolean)(implicit ctx: Context): Denotation =
470471
if (!symbol.exists || symbol.isAccessibleFrom(pre, superAccess)) this else NoDenotation
471472

472-
def atSignature(sig: Signature, site: Type)(implicit ctx: Context): SingleDenotation = {
473+
def atSignature(sig: Signature, site: Type, relaxed: Boolean)(implicit ctx: Context): SingleDenotation = {
473474
val situated = if (site == NoPrefix) this else asSeenFrom(site)
474-
if (sig matches situated.signature) this else NoDenotation
475+
val matches =
476+
if (relaxed) sig.matches(situated.signature)
477+
else sig.matchesFully(situated.signature)
478+
if (matches) this else NoDenotation
475479
}
476480

477481
def matches(other: SingleDenotation)(implicit ctx: Context): Boolean =

src/dotty/tools/dotc/core/Signature.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ case class Signature(paramsSig: List[TypeName], resSig: TypeName) {
3535
final def matches(that: Signature)(implicit ctx: Context) =
3636
if (ctx.erasedTypes) equals(that) else sameParams(that)
3737

38+
/** A signature matches fully another if it has the same parameter type names
39+
* and either one of the result type names is a wildcard or both agree.
40+
*/
41+
final def matchesFully(that: Signature)(implicit ctx: Context) =
42+
this.paramsSig == that.paramsSig &&
43+
(isWildcard(this.resSig) || isWildcard(that.resSig) || this.resSig == that.resSig)
44+
45+
/** name.toString == "" or name.toString == "_" */
46+
private def isWildcard(name: TypeName) = name.isEmpty || name == tpnme.WILDCARD
47+
3848
/** Construct a signature by prepending the signature names of the given `params`
3949
* to the parameter part of this signature.
4050
*/

0 commit comments

Comments
 (0)