summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.xml1
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala27
-rw-r--r--test/files/neg/tcpoly_ticket2101.check4
-rw-r--r--test/files/neg/tcpoly_ticket2101.scala28
-rw-r--r--test/files/pos/tcpoly_ticket2096.scala30
5 files changed, 86 insertions, 4 deletions
diff --git a/build.xml b/build.xml
index a94e018067..f34de0688c 100644
--- a/build.xml
+++ b/build.xml
@@ -189,6 +189,7 @@ PROPERTIES
<!-- if ANT_OPTS is already set by the environment, it will be unaltered,
but if it is unset it will take this default value. -->
<property name="env.ANT_OPTS" value="-Xms512M -Xmx1024M -Xss1M -XX:MaxPermSize=128M" />
+ <!-- to find max heap usage: -Xaprof ; currently at 980M for locker.comp -->
<property
name="scalacfork.jvmargs"
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index 8bf9708c0c..0ebd2018fb 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -4005,10 +4005,29 @@ A type's typeSymbol should never be inspected directly.
(res1 <:< res2) &&
tp1.isInstanceOf[ImplicitMethodType] == tp2.isInstanceOf[ImplicitMethodType])
case (PolyType(tparams1, res1), PolyType(tparams2, res2)) =>
- (tparams1.length == tparams2.length &&
- List.forall2(tparams1, tparams2)
- ((p1, p2) => p2.info.substSym(tparams2, tparams1) <:< p1.info) &&
- res1 <:< res2.substSym(tparams2, tparams1))
+ tparams1.length == tparams2.length && {
+ if(tparams1.isEmpty) res1 <:< res2 // fast-path: monomorphic nullary method type
+ else if(tparams1.head.owner.isMethod) { // fast-path: polymorphic method type -- type params cannot be captured
+ List.forall2(tparams1, tparams2)((p1, p2) =>
+ p2.info.substSym(tparams2, tparams1) <:< p1.info) &&
+ res1 <:< res2.substSym(tparams2, tparams1)
+ } else { // normalized higher-kinded type
+ //@M for an example of why we need to generate fresh symbols, see neg/tcpoly_ticket2101.scala
+ val tpsFresh = cloneSymbols(tparams1) // @M cloneSymbols(tparams2) should be equivalent -- TODO: check
+
+ (List.forall2(tparams1, tparams2)((p1, p2) =>
+ p2.info.substSym(tparams2, tpsFresh) <:< p1.info.substSym(tparams1, tpsFresh)) &&
+ res1.substSym(tparams1, tpsFresh) <:< res2.substSym(tparams2, tpsFresh))
+
+ //@M the forall in the previous test could be optimised to the following,
+ // but not worth the extra complexity since it only shaves 1s from quick.comp
+ // (List.forall2(tpsFresh/*optimisation*/, tparams2)((p1, p2) =>
+ // p2.info.substSym(tparams2, tpsFresh) <:< p1.info /*optimisation, == (p1 from tparams1).info.substSym(tparams1, tpsFresh)*/) &&
+ // this optimisation holds because inlining cloneSymbols in `val tpsFresh = cloneSymbols(tparams1)` gives:
+ // val tpsFresh = tparams1 map (_.cloneSymbol)
+ // for (tpFresh <- tpsFresh) tpFresh.setInfo(tpFresh.info.substSym(tparams1, tpsFresh))
+ }
+ }
case (TypeBounds(lo1, hi1), TypeBounds(lo2, hi2)) =>
lo2 <:< lo1 && hi1 <:< hi2
case (AnnotatedType(_,_,_), _) =>
diff --git a/test/files/neg/tcpoly_ticket2101.check b/test/files/neg/tcpoly_ticket2101.check
new file mode 100644
index 0000000000..eac582e8ba
--- /dev/null
+++ b/test/files/neg/tcpoly_ticket2101.check
@@ -0,0 +1,4 @@
+tcpoly_ticket2101.scala:2: error: type arguments [T2,X] do not conform to class T's type parameter bounds [A[Y] <: T[A,B],B]
+class T2[X] extends T[T2, X] // ill-typed
+ ^
+one error found \ No newline at end of file
diff --git a/test/files/neg/tcpoly_ticket2101.scala b/test/files/neg/tcpoly_ticket2101.scala
new file mode 100644
index 0000000000..68f061ce70
--- /dev/null
+++ b/test/files/neg/tcpoly_ticket2101.scala
@@ -0,0 +1,28 @@
+class T[A[Y] <: T[A, B], B]
+class T2[X] extends T[T2, X] // ill-typed
+// because this bound is not met:
+// Forall Y. T2[Y] <: T[T2, X]
+
+// debugging before fix:
+// def isSubType0 -->
+// case (PolyType(tparams1, res1), PolyType(tparams2, res2)) => println("<:<PT: "+((tparams1, res1), (tparams2, res2))) //@MDEBUG
+// (tparams1.length == tparams2.length &&
+// List.forall2(tparams1, tparams2)
+// ((p1, p2) => p2.info.substSym(tparams2, tparams1) <:< p1.info) &&
+// res1 <:< res2.substSym(tparams2, tparams1))
+
+// generates output:
+// <:<PT: ((List(type Y),A[Y]),(List(type Y),T[A,B]))
+// <:<PT: ((List(type X),T2[X]),(List(type Y),T[T2,X]))
+
+// however, last check should have been:
+// <:<PT: ((List(type X1),T2[X1]),(List(type Y1),T[T2,X]))
+
+// case (PolyType(tparams1, res1), PolyType(tparams2, res2)) => println("<:<PT: "+((tparams1, res1), (tparams2, res2))) //@MDEBUG
+// (tparams1.length == tparams2.length &&
+// {
+// val tpsFresh = cloneSymbols(tparams1) // @M cloneSymbols(tparams2) should be equivalent -- TODO: check
+// List.forall2(tparams1, tparams2)
+// ((p1, p2) => p2.info.substSym(tparams2, tpsFresh) <:< p1.info.substSym(tparams1, tpsFresh)) &&
+// res1.substSym(tparams1, tpsFresh) <:< res2.substSym(tparams2, tpsFresh)
+// })
diff --git a/test/files/pos/tcpoly_ticket2096.scala b/test/files/pos/tcpoly_ticket2096.scala
new file mode 100644
index 0000000000..d92589c929
--- /dev/null
+++ b/test/files/pos/tcpoly_ticket2096.scala
@@ -0,0 +1,30 @@
+// smallest expression of monad i can find
+trait MBrace[C[X] <: MBrace[C,X],A] {
+ def nest( a : A ) : C[A]
+ def flatten[T <: C[C[A]]]( bsq : T ) : C[A]
+}
+
+// a monad that is a Seq
+trait MBraceSeq[C[X] <: MBrace[C,X] with Seq[X],A] extends MBrace[C,A]
+
+// one of the simplest witnesses of monad i can find
+case class MSequitor[A]( a_ : A* ) extends Seq[A] with MBrace[MSequitor,A]
+{
+ override def nest( a : A ) = new MSequitor[A]( a )
+ override def flatten[T <: MSequitor[MSequitor[A]]]( bsq : T ) : MSequitor[A] = {
+ (new MSequitor[A]( ) /: bsq)( {
+ ( acc : MSequitor[A], e : MSequitor[A] ) => ( acc ++ e ).asInstanceOf[MSequitor[A]]
+ } )
+ }
+ override def length = a_.length
+ override def iterator = a_.iterator
+ override def apply( n : Int ) = a_.apply( n )
+}
+
+// type arguments [MSequitor,A] do not conform to trait MBraceSeq's type parameter bounds [C[_] <: MBrace[C,A] with Seq[A],A]
+// a statement of the instance relation
+class MBraceSequitor[A] extends MBraceSeq[MSequitor,A] {
+ val empty : MSequitor[A] = new MSequitor[A]( )
+ override def nest( a : A ) = empty.nest( a )
+ override def flatten[T <: MSequitor[MSequitor[A]]]( bsq : T ): MSequitor[A] = empty.flatten( bsq )
+} \ No newline at end of file