diff options
author | Martin Odersky <odersky@gmail.com> | 2014-08-12 18:03:35 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-08-12 18:04:53 +0200 |
commit | 472d7114da29c869e3fa2e97b7045b797937737b (patch) | |
tree | c2ad731b208efd982314f9a762f9a03946ea58a3 /src/dotty/tools/dotc | |
parent | 843f9769f5fc5572f06e058af65e43f81b8d432d (diff) | |
download | dotty-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/dotc')
-rw-r--r-- | src/dotty/tools/dotc/core/Denotations.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 10 |
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 */ |