diff options
author | Martin Odersky <odersky@gmail.com> | 2013-12-21 19:27:52 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-12-21 19:27:52 +0100 |
commit | edf00802ff454e6bdbe5526151cf14c68811932a (patch) | |
tree | 1e404caa7c63e7b6d5041163f30dc6fe6b5d624e /src | |
parent | c7b805f7aa5973e4e5a3644beda4162827e1b5ec (diff) | |
download | dotty-edf00802ff454e6bdbe5526151cf14c68811932a.tar.gz dotty-edf00802ff454e6bdbe5526151cf14c68811932a.tar.bz2 dotty-edf00802ff454e6bdbe5526151cf14c68811932a.zip |
Adding a subtype relationship between ()T and =>T
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/TypeComparer.scala | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index f07fcc044..0d76155f1 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -309,9 +309,9 @@ class TypeComparer(initctx: Context) extends DotClass { isSubType(tp1, tp21) && isSubType(tp1, tp22) case OrType(tp21, tp22) => isSubType(tp1, tp21) || isSubType(tp1, tp22) - case tp2 @ MethodType(_, formals1) => + case tp2 @ MethodType(_, formals2) => tp1 match { - case tp1 @ MethodType(_, formals2) => + case tp1 @ MethodType(_, formals1) => tp1.signature == tp2.signature && (if (Config.newMatch) subsumeParams(formals1, formals2, tp1.isJava, tp2.isJava) else matchingParams(formals1, formals2, tp1.isJava, tp2.isJava)) && @@ -330,7 +330,16 @@ class TypeComparer(initctx: Context) extends DotClass { false } case tp2 @ ExprType(restpe2) => - isSubType(tp1.widenExpr, restpe2) + tp1 match { + // We allow ()T to be a subtype of => T. + // We need some subtype relationship between them so that e.g. + // def toString and def toString() don't clash when seen + // as members of the same type. And it seems most logical to take + // ()T <:< => T, since everything one can do with a => T one can + // also do with a ()T by automatic () insertion. + case tp1 @ MethodType(Nil, _) => isSubType(tp1.resultType, restpe2) + case _ => isSubType(tp1.widenExpr, restpe2) + } case tp2 @ TypeBounds(lo2, hi2) => tp1 match { case tp1 @ TypeBounds(lo1, hi1) => |