Skip to content

Commit 472d711

Browse files
committed
Add matchesLoosely
For overriding checks we need a concept where a val can match a def. Normal matches does not provide this.
1 parent 843f976 commit 472d711

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ object Denotations {
202202
def matchingDenotation(site: Type, targetType: Type)(implicit ctx: Context): SingleDenotation =
203203
if (isOverloaded)
204204
atSignature(targetType.signature).matchingDenotation(site, targetType)
205-
else if (exists && !(site.memberInfo(symbol) matches targetType))
205+
else if (exists && !site.memberInfo(symbol).matchesLoosely(targetType))
206206
NoDenotation
207207
else
208208
asSingleDenotation

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,16 @@ object Types {
544544
this, that, alwaysMatchSimple = !ctx.phase.erasedTypes)
545545
}
546546

547+
/** This is the same as `matches` except that it also matches => T with T and
548+
* vice versa.
549+
*/
550+
def matchesLoosely(that: Type)(implicit ctx: Context): Boolean =
551+
(this matches that) || {
552+
val thisResult = this.widenExpr
553+
val thatResult = that.widenExpr
554+
(this eq thisResult) != (that eq thatResult) && (thisResult matchesLoosely thatResult)
555+
}
556+
547557
/** The basetype TypeRef of this type with given class symbol,
548558
* but without including any type arguments
549559
*/

0 commit comments

Comments
 (0)