diff options
author | Paul Phillips <paulp@improving.org> | 2013-05-31 03:55:46 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-05-31 04:34:31 -0700 |
commit | 3c21aa38731b5011d09207e106918e16ded8ff98 (patch) | |
tree | b747e33cebf671af969c8c0ea77334cc16414e3d | |
parent | bcd052c029129129c2364327e79c4d66eb6193ee (diff) | |
download | scala-3c21aa38731b5011d09207e106918e16ded8ff98.tar.gz scala-3c21aa38731b5011d09207e106918e16ded8ff98.tar.bz2 scala-3c21aa38731b5011d09207e106918e16ded8ff98.zip |
SI-7520 bug in subtyping.
isSubType, if given two SingleTypes, would check =:= and
stop there. It is necessary to continue with weakening the left
hand side, because (for instance) the singleton type on the
left hand side could be a refinement class carrying parents
which are themselves single or constant types.
-rw-r--r-- | src/reflect/scala/reflect/internal/tpe/TypeComparers.scala | 4 | ||||
-rw-r--r-- | test/files/pos/t7520.scala | 10 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/reflect/scala/reflect/internal/tpe/TypeComparers.scala b/src/reflect/scala/reflect/internal/tpe/TypeComparers.scala index 68844a29b0..63f17dff34 100644 --- a/src/reflect/scala/reflect/internal/tpe/TypeComparers.scala +++ b/src/reflect/scala/reflect/internal/tpe/TypeComparers.scala @@ -358,8 +358,10 @@ trait TypeComparers { /** Does type `tp1` conform to `tp2`? */ private def isSubType2(tp1: Type, tp2: Type, depth: Int): Boolean = { + def retry(lhs: Type, rhs: Type) = ((lhs ne tp1) || (rhs ne tp2)) && isSubType(lhs, rhs, depth) + if (isSingleType(tp1) && isSingleType(tp2) || isConstantType(tp1) && isConstantType(tp2)) - return (tp1 =:= tp2) + return (tp1 =:= tp2) || retry(tp1.underlying, tp2) if (tp1.isHigherKinded || tp2.isHigherKinded) return isHKSubType(tp1, tp2, depth) diff --git a/test/files/pos/t7520.scala b/test/files/pos/t7520.scala new file mode 100644 index 0000000000..747f5278e5 --- /dev/null +++ b/test/files/pos/t7520.scala @@ -0,0 +1,10 @@ +class A { + val x: Singleton with this.type = this + val y: this.type = x +} + +class B { + val x = "" + val xs: x.type with Singleton = x + val y: x.type = xs +} |