diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/files/pos/t8411/Macros_1.scala | 10 | ||||
-rw-r--r-- | test/files/pos/t8411/Test_2.scala | 4 | ||||
-rw-r--r-- | test/files/run/mirror_symbolof_x.check | 13 | ||||
-rw-r--r-- | test/files/run/mirror_symbolof_x.scala | 43 | ||||
-rw-r--r-- | test/files/run/t8428.scala | 12 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/ErrorProps.scala | 31 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/LiftableProps.scala | 8 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/TypecheckedProps.scala | 5 |
8 files changed, 121 insertions, 5 deletions
diff --git a/test/files/pos/t8411/Macros_1.scala b/test/files/pos/t8411/Macros_1.scala new file mode 100644 index 0000000000..c5319c559c --- /dev/null +++ b/test/files/pos/t8411/Macros_1.scala @@ -0,0 +1,10 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Macros { + def defaultZeroCase(pf: PartialFunction[Int, Int]): PartialFunction[Int, Int] = macro impl + def impl(c: Context)(pf: c.Tree) = { import c.universe._ + val q"{ case ..$cases }" = pf + q"{ case ..$cases case _ => 0 }" + } +} diff --git a/test/files/pos/t8411/Test_2.scala b/test/files/pos/t8411/Test_2.scala new file mode 100644 index 0000000000..a0ad30f0f5 --- /dev/null +++ b/test/files/pos/t8411/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + val pf = Macros.defaultZeroCase { case 1 => 2 } + assert(pf(2) == 0) +} diff --git a/test/files/run/mirror_symbolof_x.check b/test/files/run/mirror_symbolof_x.check new file mode 100644 index 0000000000..cc9cad7a13 --- /dev/null +++ b/test/files/run/mirror_symbolof_x.check @@ -0,0 +1,13 @@ +class Int +object C +type T +type Id +class Nothing +class Null +class Int +object C +type T +type Id +class Nothing +class Null +exception: class C not found. diff --git a/test/files/run/mirror_symbolof_x.scala b/test/files/run/mirror_symbolof_x.scala new file mode 100644 index 0000000000..8fec301f56 --- /dev/null +++ b/test/files/run/mirror_symbolof_x.scala @@ -0,0 +1,43 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{currentMirror => cm} +import scala.reflect.api.Mirror + +class C +object C + +object Test extends App { + object test1 { + val m = cm + type T = Int + type Id[X] = X + println(m.symbolOf[Int]: ru.TypeSymbol) + println(m.symbolOf[C.type]: ru.TypeSymbol) + println(m.symbolOf[T]: ru.TypeSymbol) + println(m.symbolOf[Id[_]]: ru.TypeSymbol) + println(m.symbolOf[Nothing]: ru.TypeSymbol) + println(m.symbolOf[Null]: ru.TypeSymbol) + } + + object test2 { + val m: Mirror[ru.type] = cm + type T = Int + type Id[X] = X + println(m.symbolOf[Int]: ru.TypeSymbol) + println(m.symbolOf[C.type]: ru.TypeSymbol) + println(m.symbolOf[T]: ru.TypeSymbol) + println(m.symbolOf[Id[_]]: ru.TypeSymbol) + println(m.symbolOf[Nothing]: ru.TypeSymbol) + println(m.symbolOf[Null]: ru.TypeSymbol) + } + + object test3 { + val m = ru.runtimeMirror(classOf[Int].getClass.getClassLoader) + try println(m.symbolOf[C]) + catch { case ex: ScalaReflectionException => println(s"exception: ${ex.getMessage}") } + } + + test1 + test2 + test3 +} diff --git a/test/files/run/t8428.scala b/test/files/run/t8428.scala new file mode 100644 index 0000000000..7da1207b7b --- /dev/null +++ b/test/files/run/t8428.scala @@ -0,0 +1,12 @@ +object Test extends App { + val xs = List.tabulate(4)(List(_)) + val i = xs.map(_.iterator).reduce { (a,b) => + a.hasNext + a ++ b + } + + val r1 = i.toList + val r2 = xs.flatten.toList + + assert(r1 == r2, r1) +} diff --git a/test/files/scalacheck/quasiquotes/ErrorProps.scala b/test/files/scalacheck/quasiquotes/ErrorProps.scala index 3d9b27de77..9137fe17d8 100644 --- a/test/files/scalacheck/quasiquotes/ErrorProps.scala +++ b/test/files/scalacheck/quasiquotes/ErrorProps.scala @@ -9,9 +9,10 @@ object ErrorProps extends QuasiquoteProperties("errors") { """) property("can't unquote with given rank") = fails( - "Can't unquote List[reflect.runtime.universe.Ident], consider using ..", + "Can't unquote List[StringBuilder], consider using .. or providing an implicit instance of Liftable[List[StringBuilder]]", """ - val xs = List(q"x", q"x") + import java.lang.StringBuilder + val xs: List[StringBuilder] = Nil q"$xs" """) @@ -71,9 +72,10 @@ object ErrorProps extends QuasiquoteProperties("errors") { """) property("use ... rank or provide liftable") = fails( - "Can't unquote List[List[reflect.runtime.universe.Ident]], consider using ...", + "Can't unquote List[List[StringBuilder]], consider using ... or providing an implicit instance of Liftable[List[List[StringBuilder]]]", """ - val xs = List(List(q"x", q"x")) + import java.lang.StringBuilder + val xs: List[List[StringBuilder]] = Nil q"$xs" """) @@ -172,6 +174,27 @@ object ErrorProps extends QuasiquoteProperties("errors") { tq"_" """) + property("SI-8420: don't crash on splicing of non-unliftable native type (1)") = fails( + "Can't unquote List[reflect.runtime.universe.Symbol] with .., consider omitting the dots or providing an implicit instance of Liftable[reflect.runtime.universe.Symbol]", + """ + val l: List[Symbol] = Nil + q"f(..$l)" + """) + + property("SI-8420: don't crash on splicing of non-unliftable native type (2)") = fails( + "Can't unquote List[reflect.runtime.universe.FlagSet] with .., consider omitting the dots or providing an implicit instance of Liftable[reflect.runtime.universe.FlagSet]", + """ + val l: List[FlagSet] = Nil + q"f(..$l)" + """) + + property("SI-8420: don't crash on splicing of non-unliftable native type (3)") = fails( + "Can't unquote List[reflect.runtime.universe.Modifiers] with .., consider omitting the dots or providing an implicit instance of Liftable[reflect.runtime.universe.Modifiers]", + """ + val l: List[Modifiers] = Nil + q"f(..$l)" + """) + // // Make sure a nice error is reported in this case // { import Flag._; val mods = NoMods; q"lazy $mods val x: Int" } } diff --git a/test/files/scalacheck/quasiquotes/LiftableProps.scala b/test/files/scalacheck/quasiquotes/LiftableProps.scala index 5d0eeb53c6..29fdea5c89 100644 --- a/test/files/scalacheck/quasiquotes/LiftableProps.scala +++ b/test/files/scalacheck/quasiquotes/LiftableProps.scala @@ -88,9 +88,10 @@ object LiftableProps extends QuasiquoteProperties("liftable") { assert(q"$const" ≈ q"0") } + val immutable = q"$scalapkg.collection.immutable" + property("lift list variants") = test { val lst = List(1, 2) - val immutable = q"$scalapkg.collection.immutable" assert(q"$lst" ≈ q"$immutable.List(1, 2)") assert(q"f(..$lst)" ≈ q"f(1, 2)") val llst = List(List(1), List(2)) @@ -98,6 +99,11 @@ object LiftableProps extends QuasiquoteProperties("liftable") { assert(q"f(...$llst)" ≈ q"f(1)(2)") } + property("lift list of tree") = test { + val lst = List(q"a", q"b") + assert(q"$lst" ≈ q"$immutable.List(a, b)") + } + property("lift tuple") = test { assert(q"${(1, 2)}" ≈ q"(1, 2)") assert(q"${(1, 2, 3)}" ≈ q"(1, 2, 3)") diff --git a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala index 7c4cb0306e..fb2eb69321 100644 --- a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala +++ b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala @@ -152,4 +152,9 @@ object TypecheckedProps extends QuasiquoteProperties("typechecked") { assert(name == defName) assert(rhs ≈ defRhs) } + + property("partial function") = test { + val q"{ case ..$cases }: $ascr" = typecheck(q"{ case 1 => () }: PartialFunction[Int, Unit]") + assert(cases ≈ q"{ case 1 => () }".cases) + } } |