summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-06-21 17:21:07 +0000
committerPaul Phillips <paulp@improving.org>2011-06-21 17:21:07 +0000
commita546fc8f4979a0705e62df71b905860e1ce0a89d (patch)
tree19bfa9e3351847270c3d9a419142c34261d01e27
parent4b8810d3a35bca001ccde28c24ea3000c3b47a07 (diff)
downloadscala-a546fc8f4979a0705e62df71b905860e1ce0a89d.tar.gz
scala-a546fc8f4979a0705e62df71b905860e1ce0a89d.tar.bz2
scala-a546fc8f4979a0705e62df71b905860e1ce0a89d.zip
Relaxes a typer check which fails valid code wi...
Relaxes a typer check which fails valid code with NoCommonType. If the instantiated types or type bounds do not conform, it tries normalizing the type before throwing the exception. Closes #4553. I wrote this patch with adriaan already, but bonus review by moors.
-rw-r--r--src/compiler/scala/reflect/internal/Types.scala22
-rwxr-xr-xtest/files/pos/bug4553.scala11
2 files changed, 25 insertions, 8 deletions
diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala
index ed5dd1bc72..e8b9dc0865 100644
--- a/src/compiler/scala/reflect/internal/Types.scala
+++ b/src/compiler/scala/reflect/internal/Types.scala
@@ -5574,26 +5574,32 @@ A type's typeSymbol should never be inspected directly.
* Returns list of list of bounds infos, where corresponding type
* parameters are renamed to tparams.
*/
- private def matchingBounds(tps: List[Type], tparams: List[Symbol]): List[List[Type]] =
- tps map {
+ private def matchingBounds(tps: List[Type], tparams: List[Symbol]): List[List[Type]] = {
+ def getBounds(tp: Type): List[Type] = tp match {
case PolyType(tparams1, _) if sameLength(tparams1, tparams) =>
tparams1 map (tparam => tparam.info.substSym(tparams1, tparams))
- case _ =>
- throw new NoCommonType(tps)
+ case tp =>
+ if (tp ne tp.normalize) getBounds(tp.normalize)
+ else throw new NoCommonType(tps)
}
+ tps map getBounds
+ }
/** All types in list must be polytypes with type parameter lists of
* same length as tparams.
* Returns list of instance types, where corresponding type
* parameters are renamed to tparams.
*/
- private def matchingInstTypes(tps: List[Type], tparams: List[Symbol]): List[Type] =
- tps map {
+ private def matchingInstTypes(tps: List[Type], tparams: List[Symbol]): List[Type] = {
+ def transformResultType(tp: Type): Type = tp match {
case PolyType(tparams1, restpe) if sameLength(tparams1, tparams) =>
restpe.substSym(tparams1, tparams)
- case _ =>
- throw new NoCommonType(tps)
+ case tp =>
+ if (tp ne tp.normalize) transformResultType(tp.normalize)
+ else throw new NoCommonType(tps)
}
+ tps map transformResultType
+ }
/** All types in list must be method types with equal parameter types.
* Returns list of their result types.
diff --git a/test/files/pos/bug4553.scala b/test/files/pos/bug4553.scala
new file mode 100755
index 0000000000..4eefe57b2b
--- /dev/null
+++ b/test/files/pos/bug4553.scala
@@ -0,0 +1,11 @@
+trait VectorLike[+T, +V[A] <: Vector[A]] {
+ def +[S, VResult[S] >: V[S]](v: VResult[S])
+}
+
+trait Vector[+T] extends VectorLike[T, Vector]
+trait ImmutableVector[T] extends Vector[T] with VectorLike[T, ImmutableVector]
+trait MutableVector[T] extends Vector[T] with VectorLike[T, MutableVector]
+
+object Test {
+ def f = (null: MutableVector[Int]) + (null: ImmutableVector[Int])
+}