Skip to content

Commit 57b616c

Browse files
committed
New tests
1 parent f59d1d3 commit 57b616c

File tree

10 files changed

+162
-0
lines changed

10 files changed

+162
-0
lines changed

tests/pos/t3020.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
var x = true
4+
5+
( { if (x) new scala.util.Random() } .asInstanceOf[Runnable] )
6+
}
7+
}
8+
9+

tests/pos/t3037.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package test
2+
3+
object A {
4+
println(("a" match {
5+
case "a" => 1
6+
case _ => "a"
7+
}).asInstanceOf[Object])
8+
def foo[T](x: T) = x
9+
var x: Int = 1
10+
var y: Long = 1L
11+
x = foo(x)
12+
y = foo(y)
13+
}

tests/pos/t304.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object O {
2+
def f1 = -1;
3+
def f2 = 0-1;
4+
def f3 = -f1;
5+
}

tests/pos/t3106.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Sample[A] (val d0: ((A,A)) => A) {}
2+
3+
object Sample {
4+
implicit def apply[A] (x:A): Sample[A] = {
5+
new Sample(p => p._1)
6+
}
7+
}

tests/pos/t3137.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
trait A {
2+
val C: Any
3+
}
4+
5+
class B extends A {
6+
class C
7+
object C
8+
}
9+
10+
trait AA {
11+
type C
12+
def C: Int => C
13+
}
14+
15+
class BB extends AA {
16+
case class C(v: Int)
17+
}

tests/pos/t3152.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
trait Applicative[M[_]]
2+
3+
sealed trait MA[M[_], A] {
4+
def sequence[N[_], B](implicit a: A <:< N[B], n: Applicative[N]): N[M[B]] = sys.error("stub")
5+
// def sequence3[N[_], B]()(implicit a: A <:< N[B], n: Applicative[N]): N[M[B]] = sys.error("stub")
6+
}
7+
8+
object test {
9+
implicit def ListMA[A](l: List[A]): MA[List, A] = sys.error("stub")
10+
implicit val ao: Applicative[Option] = sys.error("stub")
11+
12+
/* This compiles OK:
13+
(Nil: List[Option[Int]]).sequence3(): Option[List[Int]]
14+
*/
15+
16+
// BUG: error: immutable is not an enclosing class
17+
// !!! No line number is reported with the error
18+
(Nil: List[Option[Int]]).sequence: Option[List[Int]]
19+
(List[Option[Int]]()).sequence: Option[List[Int]]
20+
}

tests/pos/t3174.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object test {
2+
def method(): Unit = {
3+
class Foo extends AnyRef {
4+
object Color {
5+
object Blue
6+
}
7+
8+
class Board {
9+
val grid = Color.Blue
10+
}
11+
}
12+
new Foo
13+
}
14+
}

tests/pos/t3177.scala

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
trait InvariantFunctor[F[_]] {
2+
def xmap[A, B](ma: F[A], f: A => B, g: B => A): F[B]
3+
}
4+
5+
object InvariantFunctor {
6+
import Endo._
7+
8+
implicit val EndoInvariantFunctor: InvariantFunctor[Endo] = new InvariantFunctor[Endo] {
9+
def xmap[A, B](ma: Endo[A], f: A => B, g: B => A): Endo[B] = (b: B) => f(ma(g(b)))
10+
}
11+
12+
// The definition about fails with:
13+
// anon-type.scala:9: error: not found: value b
14+
// def xmap[A, B](ma: Endo[A], f: A => B, g: B => A): Endo[B] = (b: B) => f(ma(g(b)))
15+
// ^
16+
// anon-type.scala:8: error: not found: type $anon
17+
// implicit val EndoInvariantFunctor = new InvariantFunctor[Endo] {
18+
// ^
19+
20+
21+
// These both work:
22+
// implicit val EndoInvariantFunctorAscribed: InvariantFunctor[Endo] = new InvariantFunctor[Endo] {
23+
// def xmap[A, B](ma: Endo[A], f: A => B, g: B => A): Endo[B] = (b: B) => f(ma(g(b)))
24+
// }
25+
//
26+
// implicit val EndoInvariantFunctorStubbed = new InvariantFunctor[Endo] {
27+
// def xmap[A, B](ma: Endo[A], f: A => B, g: B => A): Endo[B] = error("stub")
28+
// }
29+
}
30+
31+
trait Endo[X]
32+
33+
object Endo {
34+
implicit def EndoTo[A](f: A => A): Endo[A] = new Endo[A] {
35+
def apply(a: A) = f(a)
36+
}
37+
38+
implicit def EndoFrom[A](e: Endo[A]): A => A = e.apply(_)
39+
}

tests/pos/t8023.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class C[K]
2+
class D[K]
3+
4+
object Test3 {
5+
def foo = (null: Any) match {
6+
case a: C[k] => new C[k]() // this one worked before as the info of `A` was complete
7+
// ()
8+
}
9+
}

tests/pos/t9004.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
object Main {
2+
trait AA[RR] { type R = RR; def r: R }
3+
4+
def test1(a: AA[_]) = {
5+
val f = () => a.r
6+
// The tree a.r is given the type `a.R` which normalizes
7+
// to B', where B' is a distinct symbol ("captured existential skolem")
8+
// to substitute for the reference to an existential skolem of B.
9+
//
10+
// inference of the result type of the function computes the
11+
// packed type of tree `a.r` to make sure that terms and types
12+
// local to the body of the function don't leak into its result
13+
// type. The captured existential skolem is considered to be local
14+
// so it is abstracted to its upper bound, Any.
15+
//
16+
// However, the packedType transformation need not have even considered
17+
// B', as it is clear that the type `a.R` is not local to the function
18+
// body!
19+
f: (() => a.R)
20+
21+
// The workaround is to annotate the function type, rather than
22+
// relying in inference.
23+
val g: (() => a.R) = () => a.r
24+
val g2 = () => a.r
25+
26+
()
27+
}
28+
// typer debug trace: http://rawgit.com/retronym/d5aeaf8e0a4a2e6eef4b/raw/out.html
29+
}

0 commit comments

Comments
 (0)