aboutsummaryrefslogtreecommitdiff
path: root/tests/pos
diff options
context:
space:
mode:
Diffstat (limited to 'tests/pos')
-rw-r--r--tests/pos/t2405.scala23
-rw-r--r--tests/pos/t2421.scala14
-rw-r--r--tests/pos/t2421_delitedsl.scala39
-rw-r--r--tests/pos/t2421b_pos.scala19
-rw-r--r--tests/pos/t2421c.scala17
-rwxr-xr-xtests/pos/t2425.scala15
-rw-r--r--tests/pos/t2435.scala27
-rw-r--r--tests/pos/t2441pos.scala8
-rw-r--r--tests/pos/t2444.scala15
-rw-r--r--tests/pos/t245.scala18
-rw-r--r--tests/pos/t2454.scala25
-rw-r--r--tests/pos/t247.scala26
-rwxr-xr-xtests/pos/t2484.scala19
-rw-r--r--tests/pos/t2486.scala3
14 files changed, 268 insertions, 0 deletions
diff --git a/tests/pos/t2405.scala b/tests/pos/t2405.scala
new file mode 100644
index 000000000..224b2ce83
--- /dev/null
+++ b/tests/pos/t2405.scala
@@ -0,0 +1,23 @@
+object A { implicit val x: Int = 1 }
+
+// Problem as stated in the ticket.
+object Test1 {
+ import A.{x => y}
+ implicitly[Int]
+}
+
+// Testing for the absense of shadowing #1.
+object Test2 {
+ import A.{x => y}
+ val x = 2
+ implicitly[Int]
+}
+
+// Testing for the absense of shadowing #2.
+object Test3 {
+ {
+ import A.{x => y}
+ def x: Int = 0
+ implicitly[Int]
+ }
+}
diff --git a/tests/pos/t2421.scala b/tests/pos/t2421.scala
new file mode 100644
index 000000000..2544a1cb3
--- /dev/null
+++ b/tests/pos/t2421.scala
@@ -0,0 +1,14 @@
+object Test {
+ abstract class <~<[-From, +To] extends (From => To)
+ implicit def trivial[A]: A <~< A = sys.error("")
+
+
+ trait Forcible[T]
+ implicit val forcibleInt: (Int <~< Forcible[Int]) = sys.error("")
+
+ def headProxy[P <: Forcible[Int]](implicit w: Int <~< P): P = sys.error("")
+
+ headProxy
+ // trivial[Int] should not be considered a valid implicit, since w would have type Int <~< Int,
+ // and headProxy's type parameter P cannot be instantiated to Int
+}
diff --git a/tests/pos/t2421_delitedsl.scala b/tests/pos/t2421_delitedsl.scala
new file mode 100644
index 000000000..554702a03
--- /dev/null
+++ b/tests/pos/t2421_delitedsl.scala
@@ -0,0 +1,39 @@
+trait DeliteDSL {
+ abstract class <~<[-From, +To] extends (From => To)
+ implicit def trivial[A]: A <~< A = new (A <~< A) {def apply(x: A) = x}
+
+ trait Forcible[T]
+ object Forcible {
+ def factory[T](f: T => Forcible[T]) = new (T <~< Forcible[T]){def apply(x: T) = f(x)}
+ }
+
+ case class DeliteInt(x: Int) extends Forcible[Int]
+
+ implicit val forcibleInt: DeliteDSL.this.<~<[Int,DeliteDSL.this.Forcible[Int]] =
+ Forcible.factory((x: Int) => DeliteInt(x))
+
+ import scala.collection.Traversable
+ class DeliteCollection[T](val xs: Traversable[T]) {
+ // must use existential in bound of P, instead of T itself, because we cannot both have:
+ // Test.x below: DeliteCollection[T=Int] -> P=DeliteInt <: Forcible[T=Int], as T=Int <~< P=DeliteInt
+ // Test.xAlready below: DeliteCollection[T=DeliteInt] -> P=DeliteInt <: Forcible[T=DeliteInt], as T=DeliteInt <~< P=DeliteInt
+ // this would required DeliteInt <: Forcible[Int] with Forcible[DeliteInt]
+
+ def headProxy[P <: Forcible[_]](implicit w: T <~< P): P = xs.head
+ }
+ // If T is already a proxy (it is forcible), the compiler should use
+ // forcibleIdentity to deduce that P=T. If T is Int, the compiler
+ // should use intToForcible to deduce that P=DeliteInt.
+ //
+ // Without this feature, the user must write 'xs.proxyOfFirst[DeliteInt]',
+ // with the feature they can write 'xs.proxyOfFirst', which is shorter and
+ // avoids exposing internal DELITE types to the world.
+
+ object Test {
+ val x = new DeliteCollection(List(1,2,3)).headProxy
+ // inferred: val x: Forcible[Int] = new DeliteCollection[Int](List.apply[Int](1, 2, 3)).headProxy[Forcible[Int]](forcibleInt);
+
+ val xAlready = new DeliteCollection(List(DeliteInt(1),DeliteInt(2),DeliteInt(3))).headProxy
+ // inferred: val xAlready: DeliteInt = new DeliteCollection[DeliteInt](List.apply[DeliteInt](DeliteInt(1), DeliteInt(2), DeliteInt(3))).headProxy[DeliteInt](trivial[DeliteInt]);
+ }
+}
diff --git a/tests/pos/t2421b_pos.scala b/tests/pos/t2421b_pos.scala
new file mode 100644
index 000000000..679b8a8d6
--- /dev/null
+++ b/tests/pos/t2421b_pos.scala
@@ -0,0 +1,19 @@
+object Test {
+ class A
+ class B
+ class C
+ class F[X]
+
+ def f(implicit aa: F[A]) = println(aa)
+
+ implicit def a : F[A] = new F[A]()
+ implicit def b[X <: B]: Test.F[X] = new F[X]()
+
+ f
+}
+/* bug:
+error: ambiguous implicit values:
+ both method b in object Test1 of type [X <: Test1.B]Test1.F[X]
+ and method a in object Test1 of type => Test1.F[Test1.A]
+ match expected type Test1.F[Test1.A]
+*/
diff --git a/tests/pos/t2421c.scala b/tests/pos/t2421c.scala
new file mode 100644
index 000000000..bd24cacd7
--- /dev/null
+++ b/tests/pos/t2421c.scala
@@ -0,0 +1,17 @@
+object Test {
+ class A
+ class B
+ class C
+ class F[X]
+
+ def f(implicit aa: F[A]) = println(aa)
+
+ implicit def a : F[A] = new F[A]()
+
+ // generalised from t2421b to verify we check enough
+ class G[X]
+ implicit def g[X]: Test.G[X] = new G[X]()
+ implicit def b[X <: B](implicit mx: G[X]): Test.F[X] = new F[X]()
+
+ f
+}
diff --git a/tests/pos/t2425.scala b/tests/pos/t2425.scala
new file mode 100755
index 000000000..477d5467a
--- /dev/null
+++ b/tests/pos/t2425.scala
@@ -0,0 +1,15 @@
+trait B
+class D extends B
+object Test extends App {
+ def foo[T](bar: T) = {
+ bar match {
+ case _: Array[Array[_]] => println("array 2d")
+ case _: Array[_] => println("array 1d")
+ case _ => println("something else")
+ }
+ }
+ foo(Array.fill(10)(2))
+ foo(Array.fill(10, 10)(2))
+ foo(Array.fill(10, 10, 10)(2))
+ foo(List(1, 2, 3))
+}
diff --git a/tests/pos/t2435.scala b/tests/pos/t2435.scala
new file mode 100644
index 000000000..697e9e1f2
--- /dev/null
+++ b/tests/pos/t2435.scala
@@ -0,0 +1,27 @@
+object Bug {
+ abstract class FChain {
+ type T
+
+ def chain(constant:String) =
+ new FConstant[this.type](constant, this) //removing [this.type], everything compiles
+ }
+
+ case class FConstant[E <: FChain](constant:String, tail:E) extends FChain {
+ type T = tail.T
+ }
+
+ object FNil extends FChain {
+ type T = Unit
+ }
+
+}
+
+object Test {
+ import Bug._
+ println("Compiles:")
+ val a1 = FNil.chain("a").chain("a")
+ val a2 = a1.chain("a")
+
+ println("\nDoesn't compile:")
+ val a = FNil.chain("a").chain("a").chain("a")
+}
diff --git a/tests/pos/t2441pos.scala b/tests/pos/t2441pos.scala
new file mode 100644
index 000000000..25eb2232c
--- /dev/null
+++ b/tests/pos/t2441pos.scala
@@ -0,0 +1,8 @@
+abstract class A {
+ private def foo = List(1, 2)
+}
+trait B extends A {
+ private def foo = List("a", "b")
+ // However it compiles correctly if the type is given:
+ // private def foo: List[String] = List("a", "b")
+}
diff --git a/tests/pos/t2444.scala b/tests/pos/t2444.scala
new file mode 100644
index 000000000..fac1e95d0
--- /dev/null
+++ b/tests/pos/t2444.scala
@@ -0,0 +1,15 @@
+object Test {
+
+ trait Foo
+
+ class Bar {
+ object baz extends Foo
+ }
+
+ def frob[P1, P2<:Foo](f:P1 => P2) = ()
+
+ def main(args:Array[String]) : Unit = {
+ frob((p:Bar) => p.baz)
+ }
+
+}
diff --git a/tests/pos/t245.scala b/tests/pos/t245.scala
new file mode 100644
index 000000000..570ac4178
--- /dev/null
+++ b/tests/pos/t245.scala
@@ -0,0 +1,18 @@
+class Value {}
+
+object Test {
+
+ implicit def view(v: Value): Int = 0
+
+ def foo(i: Int): Int = 0
+
+ def fun0 : Value = null
+ def fun0(i: Int ): Value = null
+
+ def fun1(i: Int ): Value = null
+ def fun1(l: Long): Value = null
+
+ foo(fun0 );
+ foo(fun1(new Value));
+
+}
diff --git a/tests/pos/t2454.scala b/tests/pos/t2454.scala
new file mode 100644
index 000000000..00f2e6f67
--- /dev/null
+++ b/tests/pos/t2454.scala
@@ -0,0 +1,25 @@
+package am;
+
+trait One[M[_]] {
+ val x : Int
+}
+
+trait Two[M[_,_]] {
+ val x : Int
+}
+
+object Test {
+ // Works.
+ val x = new Two[Map] {
+ val x = 5
+ }
+
+ val o = new One[java.util.List] {
+ val x = 1
+ }
+
+ // Does not work
+ val y = new Two[java.util.concurrent.ConcurrentHashMap] {
+ val x = 3
+ }
+}
diff --git a/tests/pos/t247.scala b/tests/pos/t247.scala
new file mode 100644
index 000000000..fdcafeb2c
--- /dev/null
+++ b/tests/pos/t247.scala
@@ -0,0 +1,26 @@
+class Order[t](less:(t,t) => Boolean,equal:(t,t) => Boolean) {}
+
+trait Map[A, B] extends scala.collection.Map[A, B] {
+ val factory:MapFactory[A]
+}
+abstract class MapFactory[A] {
+ def Empty[B]:Map[A,B];
+}
+
+class TreeMapFactory[KEY](newOrder:Order[KEY]) extends MapFactory[KEY] {
+ val order = newOrder;
+ def Empty[V] = new TreeMap[KEY,V](new TreeMapFactory[KEY](order));
+}
+
+class Tree[KEY,Entry](order:Order[KEY]) {
+ def size =0;
+}
+
+class TreeMap[KEY,VALUE](_factory:TreeMapFactory[KEY]) extends Tree[KEY,Tuple2[KEY,VALUE]](_factory.order) with scala.collection.DefaultMap[KEY, VALUE] with Map[KEY, VALUE] {
+ val factory = _factory
+ val order = _factory.order;
+ def this(newOrder:Order[KEY]) = this(new TreeMapFactory[KEY](newOrder));
+ def get(key:KEY) = null;
+ def iterator:Iterator[Tuple2[KEY,VALUE]] = null;
+ override def size = super[Tree].size
+}
diff --git a/tests/pos/t2484.scala b/tests/pos/t2484.scala
new file mode 100755
index 000000000..15165c247
--- /dev/null
+++ b/tests/pos/t2484.scala
@@ -0,0 +1,19 @@
+import concurrent.ExecutionContext.Implicits.global
+
+class Admin extends javax.swing.JApplet {
+ val jScrollPane = new javax.swing.JScrollPane (null, 0, 0)
+ def t2484: Unit = {
+ scala.concurrent.Future {jScrollPane.synchronized {
+ def someFunction () = {}
+ //scala.concurrent.ops.spawn {someFunction ()}
+ jScrollPane.addComponentListener (new java.awt.event.ComponentAdapter {override def componentShown (e: java.awt.event.ComponentEvent) = {
+ someFunction (); jScrollPane.removeComponentListener (this)}})
+ }}
+ }
+}
+// t2630.scala
+object Test {
+ def meh(xs: List[Any]): Unit = {
+ xs map { x => (new AnyRef {}) }
+ }
+}
diff --git a/tests/pos/t2486.scala b/tests/pos/t2486.scala
new file mode 100644
index 000000000..69fe4c127
--- /dev/null
+++ b/tests/pos/t2486.scala
@@ -0,0 +1,3 @@
+class A[T]
+class B extends A[Int]
+class C[T] extends A[T] { def f(t: A[T]) = t match { case x: B => () } }