aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/scala/async/run/uncheckedBounds/UncheckedBoundsSpec.scala
blob: 5eb1f32adc04d9390091559fc5cb82e5dad3e32f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package scala.async
package run
package uncheckedBounds

import org.junit.{Test, Assert}
import scala.async.TreeInterrogation

class UncheckedBoundsSpec {
  @Test def insufficientLub_SI_7694() {
    suppressingFailureBefore2_10_3 {
      eval( s"""
      object Test {
        import _root_.scala.async.run.toughtype._
        import _root_.scala.async.internal.AsyncId.{async, await}
        async {
          (if (true) await(null: L[A, A]) else await(null: L[B, B]))
        }
    }
    """, compileOptions = s"-cp ${toolboxClasspath} ")
    }
  }

  @Test def insufficientLub_SI_7694_ScalaConcurrent() {
    suppressingFailureBefore2_10_3 {
      eval( s"""
      object Test {
        import _root_.scala.async.run.toughtype._
        import _root_.scala.async.Async.{async, await}
        import scala.concurrent._
        import scala.concurrent.ExecutionContext.Implicits.global
        async {
          (if (true) await(null: Future[L[A, A]]) else await(null: Future[L[B, B]]))
        }
    }
    """, compileOptions = s"-cp ${toolboxClasspath} ")
    }
  }

  private def suppressingFailureBefore2_10_3(body: => Any) {
    try {
      body
    } catch {
      case x: Throwable =>
        // @uncheckedBounds was only introduced in 2.10.3/ 2.11.0-M5, so avoid reporting this test failure in those cases.
        scala.util.Properties.versionNumberString match {
          case "2.10.0" | "2.10.1" | "2.10.2" | "2.11.0-M4" => // ignore, the @uncheckedBounds doesn't exist yet
          case _                                            =>
            val annotationExists =
              reflect.runtime.currentMirror.staticClass("scala.reflect.internal.annotations.uncheckedBounds") == reflect.runtime.universe.NoSymbol
            if (annotationExists)
              Assert.fail("@uncheckedBounds not found in scala-reflect.jar")
            else
              Assert.fail(s"@uncheckedBounds exists, but it didn't prevent this failure: $x")
        }
    }
  }
}