From 77d1c83ff67894bf87d37bfb8982d818fdc88f73 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 17 Mar 2014 15:53:21 +0100 Subject: Fix of t0625 - compare method types Method type comparison via <:< yielded false if the signatures of the two method types differed. This is too strict, because methods can have the same parametyers but different result types and still be in a subtype relationship. We now onyl demand that the sighatures have the same parameters. --- src/dotty/tools/dotc/core/TypeComparer.scala | 8 ++++++-- tests/pending/pos/t0625.scala | 8 -------- tests/pos/t0625.scala | 8 ++++++++ 3 files changed, 14 insertions(+), 10 deletions(-) delete mode 100644 tests/pending/pos/t0625.scala create mode 100644 tests/pos/t0625.scala diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index cfb9477c3..612b78f79 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -201,7 +201,11 @@ class TypeComparer(initctx: Context) extends DotClass { def isNonBottomSubType(tp1: Type, tp2: Type): Boolean = !(tp2 isRef NothingClass) && isSubType(tp1, tp2) - def isSubType(tp1: Type, tp2: Type): Boolean = /*>|>*/ ctx.traceIndented(s"isSubType ${tp1.show} <:< ${tp2.show}", subtyping) /*<|<*/ { + private def traceInfo(tp1: Type, tp2: Type) = + s"${tp1.show} <:< ${tp2.show}" + + (if (ctx.settings.verbose.value) s"${tp1.getClass} ${tp2.getClass}" else "") + + def isSubType(tp1: Type, tp2: Type): Boolean = /*>|>*/ ctx.traceIndented(s"isSubType ${traceInfo(tp1, tp2)}", subtyping) /*<|<*/ { if (tp2 eq NoType) false else if (tp1 eq tp2) true else { @@ -467,7 +471,7 @@ class TypeComparer(initctx: Context) extends DotClass { case tp2 @ MethodType(_, formals2) => def compareMethod = tp1 match { case tp1 @ MethodType(_, formals1) => - tp1.signature == tp2.signature && + (tp1.signature sameParams tp2.signature) && (if (Config.newMatch) subsumeParams(formals1, formals2, tp1.isJava, tp2.isJava) else matchingParams(formals1, formals2, tp1.isJava, tp2.isJava)) && tp1.isImplicit == tp2.isImplicit && // needed? diff --git a/tests/pending/pos/t0625.scala b/tests/pending/pos/t0625.scala deleted file mode 100644 index 561454259..000000000 --- a/tests/pending/pos/t0625.scala +++ /dev/null @@ -1,8 +0,0 @@ -object Test { - def idMap[C[_],T](m: { def map[U](f: T => U): C[U] }): C[T] = m.map(t => t) - - def main(args: Array[String]): Unit = { - idMap(Some(5)) - idMap(Responder.constant(5)) - } -} diff --git a/tests/pos/t0625.scala b/tests/pos/t0625.scala new file mode 100644 index 000000000..561454259 --- /dev/null +++ b/tests/pos/t0625.scala @@ -0,0 +1,8 @@ +object Test { + def idMap[C[_],T](m: { def map[U](f: T => U): C[U] }): C[T] = m.map(t => t) + + def main(args: Array[String]): Unit = { + idMap(Some(5)) + idMap(Responder.constant(5)) + } +} -- cgit v1.2.3