Skip to content

Add tests #2328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/pending/neg/i1846.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Bug {
final val x = 42
val y = x
x match {case y.toString => 42 case y => 42}
}
21 changes: 21 additions & 0 deletions tests/pending/neg/i1905.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Arr[T](val underlying: scala.Array[T]) extends AnyVal {
def foo = underlying
}

abstract class SeqMonoTransforms[+A, +Repr] {
protected[this] def fromIterableWithSameElemType(): Repr
def getFIWSET: Repr = fromIterableWithSameElemType
}

class ArrOps[A](val xs: Arr[A]) extends SeqMonoTransforms[A, Arr[A]] {
def fromIterableWithSameElemType(): Arr[A] = xs
}

object Test {
def main(args: Array[String]) = {
val arr = new Arr(Array(1, 2, 3))
val t = new ArrOps(arr)
val t2 = t.getFIWSET
val x = arr.foo
}
}
18 changes: 18 additions & 0 deletions tests/pending/neg/i2104.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
case class Pair[A, B](_1: A, _2: B)

trait Cons[+H, +T]

object Cons {
def apply[H, T](h: H, t: T): Cons[H, T] = ???
def unapply[H, T](t: Cons[H, T]): Option[Pair[H, T]] = ???
}

object Test {
def main(args: Array[String]): Unit = {
Cons(Option(1), None) match {
case Cons(Some(i), None) =>
i: Int // error: found: Any(i), requires: Int
assert(i == 1)
}
}
}
33 changes: 33 additions & 0 deletions tests/pending/neg/match.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
object Test {

class Seq[T]
class List[T] extends Seq[T] { def head: T = ??? }

val ss: Seq[Int] = ???
ss match {
case ss: List[int] =>
val x = ss.head
val y: Int = x
}
}
object Test1 {

class Seq[T]
class List[T] extends Seq[T] { def head: T = ??? }

val ss: Seq[Int] = ???
ss match {
case ss: List[Int] =>
println(ss)
}
}
object Test2 {

trait A
trait B
val x: A & B = ???

(x: A) match {
case x: B =>
}
}
18 changes: 18 additions & 0 deletions tests/pending/pos/TypeIndexing.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// works in neither scalac nor dotty, but maybe could be made to work?
trait A {
type T
val t : T
}

object A {
def unapply(arg: A): Option[arg.T] = Some(arg.t)
}

object Test {
def use(a : A) = a match {
case b @ A(t)
val s: b.T = t // type mismatch.
// found t.type (with underlying type <unapply-selector>.T)
// required: a.T
}
}
7 changes: 7 additions & 0 deletions tests/pending/pos/i1793.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test {
import scala.ref.WeakReference
def unapply[T <: AnyRef](wr: WeakReference[T]): Option[T] = {
val x = wr.underlying.get
if (x != null) Some(x) else None
}
}
8 changes: 8 additions & 0 deletions tests/pending/pos/i1960.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
case class CC2[A, B](_1: A, _2: B)

object Test {
def main(args: Array[String]): Unit = {
val CC2(_, CC2(a, _)) = CC2(0, CC2(1, 2))
assert(a == 1)
}
}
2 changes: 2 additions & 0 deletions tests/pending/pos/i2032.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class foo(annotation: Any) // annotation.StaticAnnotation
@foo(new AnyRef {}) trait A
7 changes: 7 additions & 0 deletions tests/pending/pos/i2071.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test {
type PF[A, B] = PartialFunction[A, B]

val f: PF[Int, String] = {
case i => "bar"
}
}
7 changes: 7 additions & 0 deletions tests/pending/pos/match.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test {

val ss: Seq[Int] = ???
ss match {
case ss: List[Int] => ???
}
}
9 changes: 9 additions & 0 deletions tests/pending/pos/namedTypeParams.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
object Test {

def f[X, Y](x: X, y: Y): Int = ???

f[Int, String](1, "")
f[X = Int, Y = String](1, "")
f[X = Int](1, "")
f[Y = String](1, "")
}
2 changes: 2 additions & 0 deletions tests/pending/pos/t9844.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trait X[T <: X[T]] { self: T => }
object Y extends X[Y.type]
21 changes: 21 additions & 0 deletions tests/pending/run/i2072.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
trait T { lazy val x: String = "foo" }
trait U { def x: Any }
abstract class AC extends T with U // { def x: Any }

abstract class B { def x: Any }
class C extends B { def x: String = "abc" }

package p2 {
trait T1 { def f: Any }
trait T2 extends T1 { def f: Number = ??? }
trait T3 extends T1 { override def f: Integer = ??? }
class C extends T2 with T3
}

package p3 {

trait A { def f: Any }
trait B extends A { def f: String }
class C extends B { def f = "abc" }

}
43 changes: 43 additions & 0 deletions tests/pending/run/nestedEq.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Outer {

case class Inner()
case class Inner2()

val inner: Inner = new Inner
val inner2 = new Inner2

def checkInstance(o: Outer) =
o.inner.isInstanceOf[this.Inner]

def checkPattern1(i: Any) =
i match {
case _: Inner => true
case _ => false
}

def checkPattern2(i: Any) =
i match {
case Inner() => true
case _ => false
}

def checkEquals(o: Outer) =
o.inner == inner

}

object Test {

def main(args: Array[String]) = {
val o1 = new Outer
val o2 = new Outer
println(o1.inner.hashCode)
println(o2.inner.hashCode)
println(o2.inner2.hashCode)
assert(o1.checkInstance(o2))
assert(!o1.checkPattern1(o2.inner))
assert(!o1.checkPattern2(o2.inner))
assert(!o1.checkEquals(o2))
}

}
11 changes: 11 additions & 0 deletions tests/pos/i2081.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
trait Foo {
// This should not generate a $init method.
// Currently this needs to be verified by manual inspection of the bytecode.
def meth(x: Int): Int
}
trait Bar extends Foo
trait Bam

class C extends Foo with Bar {
def meth(x: Int) = x
}
12 changes: 12 additions & 0 deletions tests/pos/i2278.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
object Fluent {
trait Foo[C[_]] {
def meth1[T]() : C[T]
}
trait CC[T]

type Context[Alg[x[_]] <: Foo[x], E] = implicit Alg[CC] => CC[E]

def meth1[T]() : Context[Foo, T] = {
implicitly[Foo[CC]].meth1()
}
}