aboutsummaryrefslogtreecommitdiff
path: root/tests/untried/pos/t2060.scala
diff options
context:
space:
mode:
authorSamuel Gruetter <samuel.gruetter@epfl.ch>2014-03-12 22:44:33 +0100
committerSamuel Gruetter <samuel.gruetter@epfl.ch>2014-03-12 22:44:33 +0100
commit9ef5f6817688f814a3450126aa7383b0928e80a0 (patch)
tree5727a2f7f7fd665cefdb312af2785c692f04377c /tests/untried/pos/t2060.scala
parent194be919664447631ba55446eb4874979c908d27 (diff)
downloaddotty-9ef5f6817688f814a3450126aa7383b0928e80a0.tar.gz
dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.tar.bz2
dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.zip
add tests from scala/test/files/{pos,neg}
with explicit Unit return type
Diffstat (limited to 'tests/untried/pos/t2060.scala')
-rwxr-xr-xtests/untried/pos/t2060.scala44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/untried/pos/t2060.scala b/tests/untried/pos/t2060.scala
new file mode 100755
index 000000000..2c701150e
--- /dev/null
+++ b/tests/untried/pos/t2060.scala
@@ -0,0 +1,44 @@
+/* The problem here is that we cannot insert an implicit to
+ * add a polymorphic method which is then instantiated to the
+ * right type. When searching for the implicit in the `fails to compile
+ * line':
+ *
+ * val failure = 1.0 + new Op[Int]
+ *
+ * we reduce the problem to finding a function from Double to
+ * {+: _ >: Op[Int] <: Any}, that is, a method which takes
+ * an argument which is an Op[Int] or a supertype thereof.
+ * Class Rich is not a subtype of this structural record, because
+ * polymorphic method instantiation is not contained in subtyping.
+ * That is: The method type [I](op : Op[I]): Op[I] is not a subtype
+ * of (Op[Int]): Op[Int].
+ * At present it is unclear whether this problem can be solved.
+ */
+object Test {
+ class Op[I];
+ class IntOp extends Op[Int];
+
+ class Rich(x : Double) {
+ def + (op : IntOp): IntOp = op;
+ def + [I](op : Op[I]): Op[I] = op;
+ def plus [I](op : Op[I]): Op[I] = op;
+ }
+
+ implicit def iToRich(x : Double) =
+ new Rich(x);
+
+ // fails to compile
+ val x = 1.0 + new Op[Int]
+
+ // works as expected --
+ // problem isn't in adding new "+"
+ val a = 1.0 + new IntOp;
+
+ // works as expected --
+ // problem isn't in binding type variable I
+ val b = 1.0 plus new Op[Int];
+
+ // works as expected --
+ // problem isn't in using Rich.+[I](op : Op[I])
+ val c = iToRich(1.0) + new Op[Int];
+}