aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-08-12 18:03:35 +0200
committerMartin Odersky <odersky@gmail.com>2014-08-12 18:04:53 +0200
commit472d7114da29c869e3fa2e97b7045b797937737b (patch)
treec2ad731b208efd982314f9a762f9a03946ea58a3 /src/dotty/tools
parent843f9769f5fc5572f06e058af65e43f81b8d432d (diff)
downloaddotty-472d7114da29c869e3fa2e97b7045b797937737b.tar.gz
dotty-472d7114da29c869e3fa2e97b7045b797937737b.tar.bz2
dotty-472d7114da29c869e3fa2e97b7045b797937737b.zip
Add matchesLoosely
For overriding checks we need a concept where a val can match a def. Normal matches does not provide this.
Diffstat (limited to 'src/dotty/tools')
-rw-r--r--src/dotty/tools/dotc/core/Denotations.scala2
-rw-r--r--src/dotty/tools/dotc/core/Types.scala10
2 files changed, 11 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala
index 022230ff8..f4e9746c7 100644
--- a/src/dotty/tools/dotc/core/Denotations.scala
+++ b/src/dotty/tools/dotc/core/Denotations.scala
@@ -202,7 +202,7 @@ object Denotations {
def matchingDenotation(site: Type, targetType: Type)(implicit ctx: Context): SingleDenotation =
if (isOverloaded)
atSignature(targetType.signature).matchingDenotation(site, targetType)
- else if (exists && !(site.memberInfo(symbol) matches targetType))
+ else if (exists && !site.memberInfo(symbol).matchesLoosely(targetType))
NoDenotation
else
asSingleDenotation
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 50c729df1..e5c86ef44 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -544,6 +544,16 @@ object Types {
this, that, alwaysMatchSimple = !ctx.phase.erasedTypes)
}
+ /** This is the same as `matches` except that it also matches => T with T and
+ * vice versa.
+ */
+ def matchesLoosely(that: Type)(implicit ctx: Context): Boolean =
+ (this matches that) || {
+ val thisResult = this.widenExpr
+ val thatResult = that.widenExpr
+ (this eq thisResult) != (that eq thatResult) && (thisResult matchesLoosely thatResult)
+ }
+
/** The basetype TypeRef of this type with given class symbol,
* but without including any type arguments
*/