diff options
Diffstat (limited to 'test')
118 files changed, 1098 insertions, 300 deletions
diff --git a/test/files/jvm/si5471.check b/test/files/jvm/t5471.check index bb101b641b..bb101b641b 100644 --- a/test/files/jvm/si5471.check +++ b/test/files/jvm/t5471.check diff --git a/test/files/jvm/si5471.scala b/test/files/jvm/t5471.scala index 2efd869b61..2efd869b61 100644 --- a/test/files/jvm/si5471.scala +++ b/test/files/jvm/t5471.scala diff --git a/test/files/neg/checksensible.check b/test/files/neg/checksensible.check index ef3aee5ee4..e5f1a38d96 100644 --- a/test/files/neg/checksensible.check +++ b/test/files/neg/checksensible.check @@ -28,9 +28,6 @@ checksensible.scala:27: warning: comparing values of types Int and Unit using `= checksensible.scala:29: warning: comparing values of types Int and String using `==' will always yield false 1 == "abc" ^ -checksensible.scala:29: warning: Int and String are unrelated: they will most likely never compare equal - 1 == "abc" - ^ checksensible.scala:33: warning: comparing values of types Some[Int] and Int using `==' will always yield false Some(1) == 1 // as above ^ @@ -64,18 +61,12 @@ checksensible.scala:51: warning: comparing values of types Int and Unit using `! checksensible.scala:52: warning: comparing values of types Int and Symbol using `!=' will always yield true (1 != 'sym) ^ -checksensible.scala:52: warning: Int and Symbol are unrelated: they will most likely always compare unequal - (1 != 'sym) - ^ checksensible.scala:58: warning: comparing a fresh object using `==' will always yield false ((x: Int) => x + 1) == null ^ checksensible.scala:59: warning: comparing a fresh object using `==' will always yield false Bep == ((_: Int) + 1) ^ -checksensible.scala:59: warning: Bep.type and Int => Int are unrelated: they will most likely never compare equal - Bep == ((_: Int) + 1) - ^ checksensible.scala:61: warning: comparing a fresh object using `==' will always yield false new Object == new Object ^ @@ -91,9 +82,6 @@ checksensible.scala:66: warning: comparing values of types Int and Null using `= checksensible.scala:71: warning: comparing values of types Bip and Bop using `==' will always yield false (x1 == x2) ^ -checksensible.scala:71: warning: Bip and Bop are unrelated: they will most likely never compare equal - (x1 == x2) - ^ checksensible.scala:81: warning: comparing values of types EqEqRefTest.this.C3 and EqEqRefTest.this.Z1 using `==' will always yield false c3 == z1 ^ @@ -106,12 +94,9 @@ checksensible.scala:83: warning: comparing values of types EqEqRefTest.this.Z1 a checksensible.scala:84: warning: comparing values of types EqEqRefTest.this.C3 and String using `!=' will always yield true c3 != "abc" ^ -checksensible.scala:84: warning: EqEqRefTest.this.C3 and String are unrelated: they will most likely always compare unequal - c3 != "abc" - ^ checksensible.scala:95: warning: comparing values of types Unit and Int using `!=' will always yield true while ((c = in.read) != -1) ^ error: No warnings can be incurred under -Xfatal-warnings. -38 warnings found +33 warnings found one error found diff --git a/test/files/neg/compile-time-only-b.check b/test/files/neg/compile-time-only-b.check index 8292a0ddeb..50cdf57fb5 100644 --- a/test/files/neg/compile-time-only-b.check +++ b/test/files/neg/compile-time-only-b.check @@ -1,7 +1,13 @@ +compile-time-only-b.scala:9: error: splice must be enclosed within a reify {} block + val ignored1 = expr.splice + ^ +compile-time-only-b.scala:10: error: cannot use value except for signatures of macro implementations + val ignored2 = expr.value + ^ compile-time-only-b.scala:13: error: splice must be enclosed within a reify {} block val ignored3 = reify(fortyTwo).splice ^ compile-time-only-b.scala:14: error: cannot use value except for signatures of macro implementations val ignored4 = reify(fortyTwo).value ^ -two errors found +four errors found diff --git a/test/files/neg/macro-deprecate-idents.check b/test/files/neg/macro-deprecate-idents.check index c653eabaef..c5902aeea6 100644 --- a/test/files/neg/macro-deprecate-idents.check +++ b/test/files/neg/macro-deprecate-idents.check @@ -1,54 +1,67 @@ -macro-deprecate-idents.scala:2: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:2: error: macro is now a reserved word; usage as an identifier is disallowed val macro = ??? ^ -macro-deprecate-idents.scala:6: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:6: error: macro is now a reserved word; usage as an identifier is disallowed var macro = ??? ^ -macro-deprecate-idents.scala:10: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:10: error: macro is now a reserved word; usage as an identifier is disallowed type macro = Int ^ -macro-deprecate-idents.scala:14: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:14: error: macro is now a reserved word; usage as an identifier is disallowed class macro ^ -macro-deprecate-idents.scala:18: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:18: error: macro is now a reserved word; usage as an identifier is disallowed class macro ^ -macro-deprecate-idents.scala:22: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:22: error: macro is now a reserved word; usage as an identifier is disallowed object macro ^ -macro-deprecate-idents.scala:26: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:26: error: macro is now a reserved word; usage as an identifier is disallowed object macro ^ -macro-deprecate-idents.scala:30: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:30: error: macro is now a reserved word; usage as an identifier is disallowed trait macro ^ -macro-deprecate-idents.scala:34: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:34: error: macro is now a reserved word; usage as an identifier is disallowed trait macro ^ -macro-deprecate-idents.scala:37: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:37: error: macro is now a reserved word; usage as an identifier is disallowed package macro { ^ -macro-deprecate-idents.scala:38: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:38: error: macro is now a reserved word; usage as an identifier is disallowed package macro.bar { ^ -macro-deprecate-idents.scala:43: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:43: error: macro is now a reserved word; usage as an identifier is disallowed package macro.foo { ^ -macro-deprecate-idents.scala:48: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:48: error: macro is now a reserved word; usage as an identifier is disallowed val Some(macro) = Some(42) ^ -macro-deprecate-idents.scala:49: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:49: error: macro is now a reserved word; usage as an identifier is disallowed macro match { ^ -macro-deprecate-idents.scala:50: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:50: error: macro is now a reserved word; usage as an identifier is disallowed case macro => println(macro) ^ -macro-deprecate-idents.scala:50: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:50: error: macro is now a reserved word; usage as an identifier is disallowed case macro => println(macro) ^ -macro-deprecate-idents.scala:55: warning: macro is now a reserved word; usage as an identifier is deprecated +macro-deprecate-idents.scala:55: error: macro is now a reserved word; usage as an identifier is disallowed def macro = 2 ^ -error: No warnings can be incurred under -Xfatal-warnings. -17 warnings found -one error found +macro-deprecate-idents.scala:3: error: '=' expected but '}' found. +} +^ +macro-deprecate-idents.scala:7: error: '=' expected but '}' found. +} +^ +macro-deprecate-idents.scala:42: error: '{' expected but ';' found. +package foo { +^ +macro-deprecate-idents.scala:45: error: '{' expected but '}' found. +} +^ +macro-deprecate-idents.scala:52: error: ')' expected but '}' found. +} +^ +22 errors found diff --git a/test/files/neg/macro-reify-splice-splice.check b/test/files/neg/macro-reify-splice-splice.check new file mode 100644 index 0000000000..bd1ea7acee --- /dev/null +++ b/test/files/neg/macro-reify-splice-splice.check @@ -0,0 +1,7 @@ +Macros_1.scala:8: error: the splice cannot be resolved statically, which means there is a cross-stage evaluation involved. +cross-stage evaluations need to be invoked explicitly, so we're showing you this error. +if you're sure this is not an oversight, add scala-compiler.jar to the classpath, +import `scala.tools.reflect.Eval` and call `<your expr>.eval` instead. + { c.universe.reify(c.universe.reify("hello world")) }.splice.splice + ^ +one error found diff --git a/test/files/run/macro-reify-splice-splice.flags b/test/files/neg/macro-reify-splice-splice.flags index cd66464f2f..cd66464f2f 100644 --- a/test/files/run/macro-reify-splice-splice.flags +++ b/test/files/neg/macro-reify-splice-splice.flags diff --git a/test/files/run/macro-reify-splice-splice/Macros_1.scala b/test/files/neg/macro-reify-splice-splice/Macros_1.scala index 691f22ad07..691f22ad07 100644 --- a/test/files/run/macro-reify-splice-splice/Macros_1.scala +++ b/test/files/neg/macro-reify-splice-splice/Macros_1.scala diff --git a/test/files/run/macro-reify-splice-splice/Test_2.scala b/test/files/neg/macro-reify-splice-splice/Test_2.scala index f697da6020..f697da6020 100644 --- a/test/files/run/macro-reify-splice-splice/Test_2.scala +++ b/test/files/neg/macro-reify-splice-splice/Test_2.scala diff --git a/test/files/neg/t5426.check b/test/files/neg/t5426.check index c042cdcec3..98f3ddaaae 100644 --- a/test/files/neg/t5426.check +++ b/test/files/neg/t5426.check @@ -4,18 +4,12 @@ t5426.scala:2: warning: comparing values of types Some[Int] and Int using `==' w t5426.scala:3: warning: comparing values of types Int and Some[Int] using `==' will always yield false def f2 = 5 == Some(5) ^ -t5426.scala:3: warning: Int and Some[Int] are unrelated: they will most likely never compare equal - def f2 = 5 == Some(5) - ^ t5426.scala:8: warning: comparing values of types Int and Some[Int] using `==' will always yield false (x1 == x2) ^ -t5426.scala:8: warning: Int and Some[Int] are unrelated: they will most likely never compare equal - (x1 == x2) - ^ t5426.scala:9: warning: comparing values of types Some[Int] and Int using `==' will always yield false (x2 == x1) ^ error: No warnings can be incurred under -Xfatal-warnings. -6 warnings found +four warnings found one error found diff --git a/test/files/neg/t5663-badwarneq.check b/test/files/neg/t5663-badwarneq.check index 4b7795585b..732e4f44d0 100644 --- a/test/files/neg/t5663-badwarneq.check +++ b/test/files/neg/t5663-badwarneq.check @@ -25,9 +25,6 @@ t5663-badwarneq.scala:72: warning: ValueClass1 and Int are unrelated: they will t5663-badwarneq.scala:74: warning: comparing values of types Int and ValueClass1 using `==' will always yield false println(5 == new ValueClass1(5)) // bad ^ -t5663-badwarneq.scala:74: warning: Int and ValueClass1 are unrelated: they will never compare equal - println(5 == new ValueClass1(5)) // bad - ^ t5663-badwarneq.scala:78: warning: ValueClass2[String] and String are unrelated: they will never compare equal println(new ValueClass2("abc") == "abc") // bad ^ @@ -41,5 +38,5 @@ t5663-badwarneq.scala:82: warning: comparing values of types ValueClass3 and Int println(ValueClass3(5) == 5) // bad ^ error: No warnings can be incurred under -Xfatal-warnings. -14 warnings found +13 warnings found one error found diff --git a/test/files/neg/t6231.check b/test/files/neg/t6231.check deleted file mode 100644 index 6e107c97c7..0000000000 --- a/test/files/neg/t6231.check +++ /dev/null @@ -1,6 +0,0 @@ -t6231.scala:4: error: Implementation restriction: local trait Bug$X$1 is unable to automatically capture the -free variable value ev$1 on behalf of <$anon: Function0>. You can manually assign it to a val inside the trait, -and refer to that val in <$anon: Function0>. For more details, see SI-6231. - def qux = { () => ev } - ^ -one error found diff --git a/test/files/neg/t6231.flags b/test/files/neg/t6231.flags deleted file mode 100644 index ac96850b69..0000000000 --- a/test/files/neg/t6231.flags +++ /dev/null @@ -1 +0,0 @@ --Ydelambdafy:inline
\ No newline at end of file diff --git a/test/files/neg/t6355.check b/test/files/neg/t6355.check deleted file mode 100644 index 607829d99a..0000000000 --- a/test/files/neg/t6355.check +++ /dev/null @@ -1,7 +0,0 @@ -t6355.scala:12: error: implementation restriction: applyDynamic cannot be overloaded except by methods with different numbers of type parameters, e.g. applyDynamic[T1](method: String)(arg: T1) and applyDynamic[T1, T2](method: String)(arg1: T1, arg2: T2) - def applyDynamic(name: String)(x: Int): Int = 2 - ^ -t6355.scala:18: error: implementation restriction: applyDynamic cannot be overloaded except by methods with different numbers of type parameters, e.g. applyDynamic[T1](method: String)(arg: T1) and applyDynamic[T1, T2](method: String)(arg1: T1, arg2: T2) - def applyDynamic[T1, T2](name: String)(x: String, y: T1, z: T2): Int = 3 - ^ -two errors found diff --git a/test/files/neg/t6355a.check b/test/files/neg/t6355a.check new file mode 100644 index 0000000000..5768d31f0b --- /dev/null +++ b/test/files/neg/t6355a.check @@ -0,0 +1,7 @@ +t6355a.scala:12: error: implementation restriction: applyDynamic cannot be overloaded except by methods with different numbers of type parameters, e.g. applyDynamic[T1](method: String)(arg: T1) and applyDynamic[T1, T2](method: String)(arg1: T1, arg2: T2) + def applyDynamic(name: String)(x: Int): Int = 2 + ^ +t6355a.scala:18: error: implementation restriction: applyDynamic cannot be overloaded except by methods with different numbers of type parameters, e.g. applyDynamic[T1](method: String)(arg: T1) and applyDynamic[T1, T2](method: String)(arg1: T1, arg2: T2) + def applyDynamic[T1, T2](name: String)(x: String, y: T1, z: T2): Int = 3 + ^ +two errors found diff --git a/test/files/neg/t6355.scala b/test/files/neg/t6355a.scala index 0500ed04c6..0500ed04c6 100644 --- a/test/files/neg/t6355.scala +++ b/test/files/neg/t6355a.scala diff --git a/test/files/neg/t6355b.check b/test/files/neg/t6355b.check new file mode 100644 index 0000000000..f827f07e53 --- /dev/null +++ b/test/files/neg/t6355b.check @@ -0,0 +1,11 @@ +t6355b.scala:14: error: value applyDynamic is not a member of A +error after rewriting to x.<applyDynamic: error>("bippy") +possible cause: maybe a wrong Dynamic method signature? + println(x.bippy(42)) + ^ +t6355b.scala:15: error: value applyDynamic is not a member of A +error after rewriting to x.<applyDynamic: error>("bippy") +possible cause: maybe a wrong Dynamic method signature? + println(x.bippy("42")) + ^ +two errors found diff --git a/test/files/neg/t6355b.scala b/test/files/neg/t6355b.scala new file mode 100644 index 0000000000..5f3c97cb0c --- /dev/null +++ b/test/files/neg/t6355b.scala @@ -0,0 +1,17 @@ +import scala.language.dynamics + +class A extends Dynamic { + def selectDynamic(method: String): B = new B(method) +} +class B(method: String) { + def apply(x: Int) = s"$method(x: Int) called with x = $x" + def apply(x: String) = s"""$method(x: String) called with x = "$x"""" +} + +object Test { + def main(args: Array[String]): Unit = { + val x = new A + println(x.bippy(42)) + println(x.bippy("42")) + } +} diff --git a/test/files/neg/t6539.check b/test/files/neg/t6539.check index b647636338..8c94a8ad4c 100644 --- a/test/files/neg/t6539.check +++ b/test/files/neg/t6539.check @@ -7,4 +7,10 @@ Test_2.scala:3: error: cto may only be used as an argument to m Test_2.scala:5: error: cto may only be used as an argument to m M.cto // error ^ -three errors found +Test_2.scala:9: error: splice must be enclosed within a reify {} block + val splice = expr.splice + ^ +Test_2.scala:10: error: cannot use value except for signatures of macro implementations + val value = expr.value + ^ +5 errors found diff --git a/test/files/neg/t6920.check b/test/files/neg/t6920.check new file mode 100644 index 0000000000..ee4eafb83e --- /dev/null +++ b/test/files/neg/t6920.check @@ -0,0 +1,6 @@ +t6920.scala:9: error: too many arguments for method applyDynamicNamed: (values: Seq[(String, Any)])String +error after rewriting to CompilerError.this.test.applyDynamicNamed("crushTheCompiler")(scala.Tuple2("a", 1), scala.Tuple2("b", 2)) +possible cause: maybe a wrong Dynamic method signature? + test.crushTheCompiler(a = 1, b = 2) + ^ +one error found diff --git a/test/files/neg/t6920.scala b/test/files/neg/t6920.scala new file mode 100644 index 0000000000..b79d641698 --- /dev/null +++ b/test/files/neg/t6920.scala @@ -0,0 +1,10 @@ +import scala.language.dynamics + +class DynTest extends Dynamic { + def applyDynamicNamed(name: String)(values: Seq[(String, Any)]) = "test" +} + +class CompilerError { + val test = new DynTest + test.crushTheCompiler(a = 1, b = 2) +}
\ No newline at end of file diff --git a/test/files/neg/t7756b.check b/test/files/neg/t7756b.check index e764783241..2817a7e230 100644 --- a/test/files/neg/t7756b.check +++ b/test/files/neg/t7756b.check @@ -1,9 +1,6 @@ t7756b.scala:3: warning: comparing values of types Int and String using `==' will always yield false case _ => 0 == "" ^ -t7756b.scala:3: warning: Int and String are unrelated: they will most likely never compare equal - case _ => 0 == "" - ^ error: No warnings can be incurred under -Xfatal-warnings. -two warnings found +one warning found one error found diff --git a/test/files/neg/t8006.check b/test/files/neg/t8006.check new file mode 100644 index 0000000000..fbac26e3ad --- /dev/null +++ b/test/files/neg/t8006.check @@ -0,0 +1,6 @@ +t8006.scala:3: error: too many arguments for method applyDynamicNamed: (value: (String, Any))String +error after rewriting to X.this.d.applyDynamicNamed("meth")(scala.Tuple2("value1", 10), scala.Tuple2("value2", 100)) +possible cause: maybe a wrong Dynamic method signature? + d.meth(value1 = 10, value2 = 100) // two arguments here, but only one is allowed + ^ +one error found diff --git a/test/files/neg/t8006.scala b/test/files/neg/t8006.scala new file mode 100644 index 0000000000..b2f71c1587 --- /dev/null +++ b/test/files/neg/t8006.scala @@ -0,0 +1,8 @@ +object X { + val d = new D + d.meth(value1 = 10, value2 = 100) // two arguments here, but only one is allowed +} +import language.dynamics +class D extends Dynamic { + def applyDynamicNamed(name: String)(value: (String, Any)) = name +}
\ No newline at end of file diff --git a/test/files/neg/t8104.check b/test/files/neg/t8104.check new file mode 100644 index 0000000000..69b3461bd5 --- /dev/null +++ b/test/files/neg/t8104.check @@ -0,0 +1,4 @@ +Test_2.scala:20: error: could not find implicit value for parameter e: Generic.Aux[Test.C,(Int, Int)] + implicitly[Generic.Aux[C, (Int, Int)]] + ^ +one error found diff --git a/test/files/neg/t8104/Macros_1.scala b/test/files/neg/t8104/Macros_1.scala new file mode 100644 index 0000000000..21d81a3687 --- /dev/null +++ b/test/files/neg/t8104/Macros_1.scala @@ -0,0 +1,11 @@ +import scala.reflect.macros.WhiteboxContext + +object Macros { + def impl[T](c: WhiteboxContext)(implicit T: c.WeakTypeTag[T]) = { + import c.universe._ + import definitions._ + val fields = T.tpe.declarations.toList.collect{ case x: TermSymbol if x.isVal && x.isCaseAccessor => x } + val Repr = appliedType(TupleClass(fields.length).asType.toType, fields.map(_.typeSignature)) + q"new Generic[$T]{ type Repr = $Repr }" + } +}
\ No newline at end of file diff --git a/test/files/neg/t8104/Test_2.scala b/test/files/neg/t8104/Test_2.scala new file mode 100644 index 0000000000..585f76c00f --- /dev/null +++ b/test/files/neg/t8104/Test_2.scala @@ -0,0 +1,21 @@ +trait Generic[T] { type Repr } +object Generic { + type Aux[T, Repr0] = Generic[T] { type Repr = Repr0 } + import scala.language.experimental.macros + implicit def materializeGeneric[T]: Generic[T] = macro Macros.impl[T] +} + +object Test extends App { + case class C(x: Int, y: Int) + + import scala.reflect.runtime.universe._ + def reprify[T, Repr](x: T)(implicit generic: Generic.Aux[T, Repr], tag: TypeTag[Repr]) = println(tag) + reprify(C(40, 2)) + + // this is a compilation error at the moment as explained in SI-8104 + // because matchesPt in implicit search says that depoly(<type of materializeGeneric>) isn't a subtype of Generic.Aux[C, (Int, Int)] + // which is rightfully so, because depoly only replaces type parameters, not type members with wildcard types + // however in the future we might want to relax the matchesPt check, so this might start compiling + // therefore, if you've broken this test, then you should be happy, because most likely you've just enabled an interesting use case! + implicitly[Generic.Aux[C, (Int, Int)]] +} diff --git a/test/files/pos/attachments-typed-another-ident/Impls_1.scala b/test/files/pos/attachments-typed-another-ident/Impls_1.scala index f84e56d714..6271359921 100644 --- a/test/files/pos/attachments-typed-another-ident/Impls_1.scala +++ b/test/files/pos/attachments-typed-another-ident/Impls_1.scala @@ -8,7 +8,7 @@ object Macros { import c.universe._ val ident = Ident(TermName("bar")) updateAttachment MyAttachment assert(ident.attachments.get[MyAttachment.type].isDefined, ident.attachments) - val typed = c.typeCheck(ident) + val typed = c.typecheck(ident) assert(typed.attachments.get[MyAttachment.type].isDefined, typed.attachments) c.Expr[Int](typed) } diff --git a/test/files/pos/attachments-typed-ident/Impls_1.scala b/test/files/pos/attachments-typed-ident/Impls_1.scala index 11d0f65844..f24ea88a5d 100644 --- a/test/files/pos/attachments-typed-ident/Impls_1.scala +++ b/test/files/pos/attachments-typed-ident/Impls_1.scala @@ -8,7 +8,7 @@ object Macros { import c.universe._ val ident = Ident(TermName("bar")) updateAttachment MyAttachment assert(ident.attachments.get[MyAttachment.type].isDefined, ident.attachments) - val typed = c.typeCheck(ident) + val typed = c.typecheck(ident) assert(typed.attachments.get[MyAttachment.type].isDefined, typed.attachments) c.Expr[Int](typed) } diff --git a/test/files/pos/t5508-min-okay.scala b/test/files/pos/t5508-min-okay.scala new file mode 100644 index 0000000000..3a38b9c5ea --- /dev/null +++ b/test/files/pos/t5508-min-okay.scala @@ -0,0 +1,6 @@ +object Test { + trait NestedTrait { // must be nested and a trait + private val _st : Int = 0 // crashes if changed to private[this] + val escape = { () => _st } + } +} diff --git a/test/files/pos/t5508-min-okay2.scala b/test/files/pos/t5508-min-okay2.scala new file mode 100644 index 0000000000..935f28609c --- /dev/null +++ b/test/files/pos/t5508-min-okay2.scala @@ -0,0 +1,4 @@ +trait TopTrait { // must be nested and a trait + private[this] val _st : Int = 0 // crashes if TopTrait is not top level + val escape = { () => _st } +} diff --git a/test/files/pos/t5508-min.scala b/test/files/pos/t5508-min.scala new file mode 100644 index 0000000000..f59d2bd6ad --- /dev/null +++ b/test/files/pos/t5508-min.scala @@ -0,0 +1,6 @@ +object Test { + trait NestedTrait { // must be nested and a trait + private[this] val _st : Int = 0 // must be private[this] + val escape = { () => _st } + } +} diff --git a/test/files/pos/t5508.scala b/test/files/pos/t5508.scala new file mode 100644 index 0000000000..2b49758045 --- /dev/null +++ b/test/files/pos/t5508.scala @@ -0,0 +1,83 @@ +package TestTestters + +trait Test1 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = identity(_st) + } +} + +object Base1 { + trait Test2 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = identity(_st) + } + } +} + +class Test3 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = 1 + } +} + +object Base2 { + class Test4 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = 1 + } + } +} + +class Base3 { + trait Test5 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = 1 + } + } +} + +object Base4 { + trait Test6 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => () + } + } +} + +object Base5 { + trait Test7 { + private[this] var _st : Int = 0 + def close = () => { + _st = 1 + } + } +} + +object Base6 { + class Test8 { + private[this] var _st : Int = 0 + def close = () => { + _st = 1 + } + } +} + +object Base7 { + trait Test9 { + var st : Int = 0 + def close = () => { + st = 1 + } + } +} diff --git a/test/files/neg/t6231.scala b/test/files/pos/t6231.scala index 1e5b4e0e1a..1e5b4e0e1a 100644 --- a/test/files/neg/t6231.scala +++ b/test/files/pos/t6231.scala diff --git a/test/files/pos/t6231b.scala b/test/files/pos/t6231b.scala new file mode 100644 index 0000000000..b4ddfe785b --- /dev/null +++ b/test/files/pos/t6231b.scala @@ -0,0 +1,8 @@ +class Test { + def f1(t: String) = { + trait T { + def xs = Nil map (_ => t) + } + () + } +} diff --git a/test/files/pos/t7377/Macro_1.scala b/test/files/pos/t7377/Macro_1.scala index bb7ffb0f10..7280cfeaf5 100644 --- a/test/files/pos/t7377/Macro_1.scala +++ b/test/files/pos/t7377/Macro_1.scala @@ -2,6 +2,6 @@ import language.experimental._ import reflect.macros.BlackboxContext object M { - def noopImpl[A](c: BlackboxContext)(expr: c.Expr[A]): c.Expr[A] = c.Expr(c.typeCheck(c.resetLocalAttrs(expr.tree))) + def noopImpl[A](c: BlackboxContext)(expr: c.Expr[A]): c.Expr[A] = c.Expr(c.typecheck(c.resetLocalAttrs(expr.tree))) def noop[A](expr: A): A = macro noopImpl[A] } diff --git a/test/files/pos/t7461/Macros_1.scala b/test/files/pos/t7461/Macros_1.scala index 126e9c067a..89ae7c70e3 100644 --- a/test/files/pos/t7461/Macros_1.scala +++ b/test/files/pos/t7461/Macros_1.scala @@ -4,7 +4,7 @@ import language.experimental.macros object Macros { def impl(c: BlackboxContext) = { import c.universe._ - val wut = c.typeCheck(Select(Literal(Constant(10)), newTermName("$minus")), silent = true) + val wut = c.typecheck(Select(Literal(Constant(10)), newTermName("$minus")), silent = true) // println(showRaw(wut, printIds = true, printTypes = true)) c.Expr[Unit](q"()") } diff --git a/test/files/pos/t8120.scala b/test/files/pos/t8120.scala new file mode 100644 index 0000000000..e06f38d5db --- /dev/null +++ b/test/files/pos/t8120.scala @@ -0,0 +1,9 @@ +object A { + class C { + def m(a: Nothing): Int = 0 + } + implicit class RichAny(a: Any) { + def m(a: Any): Int = 0 + } + (new C).m({ case (x, y) => x } : Any => Any) +} diff --git a/test/files/run/idempotency-case-classes.scala b/test/files/run/idempotency-case-classes.scala index 4da8393cb6..81e119582b 100644 --- a/test/files/run/idempotency-case-classes.scala +++ b/test/files/run/idempotency-case-classes.scala @@ -10,7 +10,7 @@ object Test extends App { } println(casee.eval) val tb = cm.mkToolBox() - val tcasee = tb.typeCheck(casee.tree) + val tcasee = tb.typecheck(casee.tree) println(tcasee) val rtcasee = tb.resetAllAttrs(tcasee) try { diff --git a/test/files/run/idempotency-extractors.scala b/test/files/run/idempotency-extractors.scala index fe033295f5..b66b043be1 100644 --- a/test/files/run/idempotency-extractors.scala +++ b/test/files/run/idempotency-extractors.scala @@ -10,7 +10,7 @@ object Test extends App { } println(extractor.eval) val tb = cm.mkToolBox() - val textractor = tb.typeCheck(extractor.tree) + val textractor = tb.typecheck(extractor.tree) println(textractor) val rtextractor = tb.resetAllAttrs(textractor) try { diff --git a/test/files/run/idempotency-labels.scala b/test/files/run/idempotency-labels.scala index 82d009751a..f1a185d3d0 100644 --- a/test/files/run/idempotency-labels.scala +++ b/test/files/run/idempotency-labels.scala @@ -11,7 +11,7 @@ object Test extends App { } println(label.eval) val tb = cm.mkToolBox() - val tlabel = tb.typeCheck(label.tree) + val tlabel = tb.typecheck(label.tree) println(tlabel) val rtlabel = tb.resetAllAttrs(tlabel) try { diff --git a/test/files/run/idempotency-lazy-vals.scala b/test/files/run/idempotency-lazy-vals.scala index 3531f9ff4b..e763f2f3f4 100644 --- a/test/files/run/idempotency-lazy-vals.scala +++ b/test/files/run/idempotency-lazy-vals.scala @@ -15,7 +15,7 @@ object Test extends App { } println(lazee.eval) val tb = cm.mkToolBox() - val tlazee = tb.typeCheck(lazee.tree) + val tlazee = tb.typecheck(lazee.tree) println(tlazee) val rtlazee = tb.resetAllAttrs(tlazee) try { diff --git a/test/files/run/idempotency-this.scala b/test/files/run/idempotency-this.scala index 5cd4226326..2db1efd2d1 100644 --- a/test/files/run/idempotency-this.scala +++ b/test/files/run/idempotency-this.scala @@ -9,7 +9,7 @@ object Test extends App { } println(thiss.eval) val tb = cm.mkToolBox() - val tthiss = tb.typeCheck(thiss.tree) + val tthiss = tb.typecheck(thiss.tree) println(tthiss) println(showRaw(tthiss)) val rtthiss = tb.resetAllAttrs(tthiss) diff --git a/test/files/run/macro-default-params.check b/test/files/run/macro-default-params.check new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/test/files/run/macro-default-params.check @@ -0,0 +1 @@ +0 diff --git a/test/files/run/macro-default-params/Macros_1.scala b/test/files/run/macro-default-params/Macros_1.scala new file mode 100644 index 0000000000..47780ea4b8 --- /dev/null +++ b/test/files/run/macro-default-params/Macros_1.scala @@ -0,0 +1,27 @@ +import scala.language.experimental.macros +import scala.reflect.macros.WhiteboxContext + +object Macros { + def id[A]: A = null.asInstanceOf[A] + + def foo: Any = macro impl + def impl(c: WhiteboxContext): c.Tree = { + import c.universe._ + import Flag._ + + lazy val tpe = TypeTree(typeOf[Int]) + + /* If we used this line instead, it would work! */ + // lazy val tpe = tq"Int" + + lazy val param: ValDef = { + val p1 = q"val a: ${tpe.duplicate} = Macros.id[${tpe.duplicate}]" + ValDef(Modifiers(DEFAULTPARAM), p1.name, p1.tpt, p1.rhs) + } + + q""" + class C { def f($param) = a } + println(new C().f()) + """ + } +} diff --git a/test/files/run/macro-default-params/Test_2.scala b/test/files/run/macro-default-params/Test_2.scala new file mode 100644 index 0000000000..5d19639cdd --- /dev/null +++ b/test/files/run/macro-default-params/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + Macros.foo +} diff --git a/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala index ebd80c02ba..8f7a34a10a 100644 --- a/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala +++ b/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala @@ -26,7 +26,7 @@ object QueryableMacros{ import treeBuild._ val element_type = implicitly[c.WeakTypeTag[S]].tpe val foo = c.Expr[ru.Expr[Queryable[S]]]( - c.reifyTree( mkRuntimeUniverseRef, EmptyTree, c.typeCheck( + c.reifyTree( mkRuntimeUniverseRef, EmptyTree, c.typecheck( Utils[c.type](c).removeDoubleReify( Apply(Select(c.prefix.tree, TermName( name )), List( projection.tree )) ).asInstanceOf[Tree] diff --git a/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala index ebd80c02ba..8f7a34a10a 100644 --- a/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala +++ b/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala @@ -26,7 +26,7 @@ object QueryableMacros{ import treeBuild._ val element_type = implicitly[c.WeakTypeTag[S]].tpe val foo = c.Expr[ru.Expr[Queryable[S]]]( - c.reifyTree( mkRuntimeUniverseRef, EmptyTree, c.typeCheck( + c.reifyTree( mkRuntimeUniverseRef, EmptyTree, c.typecheck( Utils[c.type](c).removeDoubleReify( Apply(Select(c.prefix.tree, TermName( name )), List( projection.tree )) ).asInstanceOf[Tree] diff --git a/test/files/run/macro-reify-splice-splice.check b/test/files/run/macro-reify-splice-splice.check deleted file mode 100644 index 3b18e512db..0000000000 --- a/test/files/run/macro-reify-splice-splice.check +++ /dev/null @@ -1 +0,0 @@ -hello world diff --git a/test/files/run/macro-reify-unreify/Macros_1.scala b/test/files/run/macro-reify-unreify/Macros_1.scala index d1e71b3311..055959018a 100644 --- a/test/files/run/macro-reify-unreify/Macros_1.scala +++ b/test/files/run/macro-reify-unreify/Macros_1.scala @@ -9,7 +9,7 @@ object Macros { import treeBuild._ val world = c.reifyTree(mkRuntimeUniverseRef, EmptyTree, s.tree) - val greeting = c.reifyTree(mkRuntimeUniverseRef, EmptyTree, c.typeCheck(Apply(Select(Literal(Constant("hello ")), TermName("$plus")), List(c.unreifyTree(world))))) + val greeting = c.reifyTree(mkRuntimeUniverseRef, EmptyTree, c.typecheck(Apply(Select(Literal(Constant("hello ")), TermName("$plus")), List(c.unreifyTree(world))))) val typedGreeting = c.Expr[String](greeting) c.universe.reify { diff --git a/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala b/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala index 9f7d6f641c..ce937671cc 100644 --- a/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala +++ b/test/files/run/macro-typecheck-implicitsdisabled/Impls_Macros_1.scala @@ -5,7 +5,7 @@ object Macros { import c.universe._ val tree1 = Apply(Select(Literal(Constant(1)), TermName("$minus$greater")), List(Literal(Constant(2)))) - val ttree1 = c.typeCheck(tree1, withImplicitViewsDisabled = false) + val ttree1 = c.typecheck(tree1, withImplicitViewsDisabled = false) c.Expr[String](Literal(Constant(ttree1.toString))) } @@ -16,7 +16,7 @@ object Macros { try { val tree2 = Apply(Select(Literal(Constant(1)), TermName("$minus$greater")), List(Literal(Constant(2)))) - val ttree2 = c.typeCheck(tree2, withImplicitViewsDisabled = true) + val ttree2 = c.typecheck(tree2, withImplicitViewsDisabled = true) c.Expr[String](Literal(Constant(ttree2.toString))) } catch { case ex: Throwable => diff --git a/test/files/run/macro-typecheck-macrosdisabled.check b/test/files/run/macro-typecheck-macrosdisabled.check index e0e880ab66..0579a4f4c8 100644 --- a/test/files/run/macro-typecheck-macrosdisabled.check +++ b/test/files/run/macro-typecheck-macrosdisabled.check @@ -1,4 +1,4 @@ -{ +({ val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe; val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(this.getClass().getClassLoader()); $u.Expr.apply[Int(2)]($m, { @@ -28,5 +28,5 @@ }; new $typecreator2() })) -} +}: reflect.runtime.universe.Expr[Int]) ru.reify[Int](2) diff --git a/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala b/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala index 41e58e0e4d..45b9a4fcc8 100644 --- a/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala +++ b/test/files/run/macro-typecheck-macrosdisabled/Impls_Macros_1.scala @@ -6,7 +6,7 @@ object Macros { val ru = Select(Select(Select(Select(Ident(TermName("scala")), TermName("reflect")), TermName("runtime")), TermName("package")), TermName("universe")) val tree1 = Apply(Select(ru, TermName("reify")), List(Literal(Constant(2)))) - val ttree1 = c.typeCheck(tree1, withMacrosDisabled = false) + val ttree1 = c.typecheck(tree1, withMacrosDisabled = false) c.Expr[String](Literal(Constant(ttree1.toString))) } @@ -22,7 +22,7 @@ object Macros { build.setTypeSignature(ru, rutpe) val tree2 = Apply(Select(Ident(ru), TermName("reify")), List(Literal(Constant(2)))) - val ttree2 = c.typeCheck(tree2, withMacrosDisabled = true) + val ttree2 = c.typecheck(tree2, withMacrosDisabled = true) c.Expr[String](Literal(Constant(ttree2.toString))) } diff --git a/test/files/run/macro-typecheck-macrosdisabled2.check b/test/files/run/macro-typecheck-macrosdisabled2.check index 347dfec1dc..c6e1c08d5d 100644 --- a/test/files/run/macro-typecheck-macrosdisabled2.check +++ b/test/files/run/macro-typecheck-macrosdisabled2.check @@ -1,4 +1,4 @@ -{ +({ val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe; val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(this.getClass().getClassLoader()); $u.Expr.apply[Array[Int]]($m, { @@ -28,5 +28,5 @@ }; new $typecreator2() })) -} +}: reflect.runtime.universe.Expr[Array[Int]]) ru.reify[Array[Int]](scala.Array.apply(2)) diff --git a/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala b/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala index 3d12020109..d37a654957 100644 --- a/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala +++ b/test/files/run/macro-typecheck-macrosdisabled2/Impls_Macros_1.scala @@ -6,7 +6,7 @@ object Macros { val ru = Select(Select(Select(Select(Ident(TermName("scala")), TermName("reflect")), TermName("runtime")), TermName("package")), TermName("universe")) val tree1 = Apply(Select(ru, TermName("reify")), List(Apply(Select(Ident(TermName("scala")), TermName("Array")), List(Literal(Constant(2)))))) - val ttree1 = c.typeCheck(tree1, withMacrosDisabled = false) + val ttree1 = c.typecheck(tree1, withMacrosDisabled = false) c.Expr[String](Literal(Constant(ttree1.toString))) } @@ -22,7 +22,7 @@ object Macros { build.setTypeSignature(ru, rutpe) val tree2 = Apply(Select(Ident(ru), TermName("reify")), List(Apply(Select(Ident(TermName("scala")), TermName("Array")), List(Literal(Constant(2)))))) - val ttree2 = c.typeCheck(tree2, withMacrosDisabled = true) + val ttree2 = c.typecheck(tree2, withMacrosDisabled = true) c.Expr[String](Literal(Constant(ttree2.toString))) } diff --git a/test/files/run/mutable-anyrefmap.scala b/test/files/run/mutable-anyrefmap.scala deleted file mode 100644 index ff615d0daf..0000000000 --- a/test/files/run/mutable-anyrefmap.scala +++ /dev/null @@ -1,91 +0,0 @@ -object Test extends App { - - import scala.collection.mutable.HashMap; - import scala.collection.mutable.AnyRefMap; - - val keys = Array( - null, "perch", "herring", "salmon", "pike", "cod", "" - ) - - val rn = new scala.util.Random(42L) - var arm = AnyRefMap.empty[String, Int] - val hm = HashMap.empty[String, Int] - - def checkConsistent = hm.forall{ case (k,v) => arm.get(k).exists(_ == v) } - - assert { - (0 to 10000).forall{ i => - val k = keys(rn.nextInt(keys.length)) - if (rn.nextInt(100) < 2) arm = arm.clone() - if (rn.nextInt(100) < 5) arm.repack() - if (rn.nextBoolean) { - hm += ((k, i)) - rn.nextInt(6) match { - case 0 => arm += ((k, i)) - case 1 => arm += (k, i) - case 2 => arm(k) = i - case 3 => arm.put(k,i) - case 4 => arm ++= List((k,i)) - case _ => if (!arm.contains(k)) arm.getOrElseUpdate(k,i) - else arm += (k,i) - } - } - else { - hm -= k - rn.nextInt(2) match { - case 0 => arm -= k - case _ => arm --= List(k) - } - } - checkConsistent - } - } - - assert { - val mapped = - arm.map{ case (k,v) => (if (k==null) "" else k+k) -> v.toString } - mapped.getClass == arm.getClass - } - - assert { - val arm2 = new AnyRefMap[java.lang.Integer,Unit](2000000) - for (i <- 0 until 1000000) arm2(java.lang.Integer.valueOf(i)) = () - - arm2.size == 1000000 && - (0 to 1100000 by 100000).map(java.lang.Integer.valueOf).forall(i => (arm2 contains i) == i < 1000000) - } - - arm = AnyRefMap("heron" -> 22, "dove" -> 5, "budgie" -> 0) - - assert{ - var s = "" - arm.foreachKey(s += _) - - s.length == "herondovebudgie".length && - s.contains("heron") && - s.contains("dove") && - s.contains("budgie") - } - - assert{ var s = 0L; arm.foreachValue(s += _); s == 27L } - - assert { - val m2 = arm.mapValuesNow(_+2) - arm.transformValues(_+2) - m2 == arm && !(m2 eq arm) && (for ((_,v) <- arm) yield v).sum == 33L - } - - assert { - val arm2 = new AnyRefMap[String, String](x => if (x==null) "null" else x) - arm2 += ("cod" -> "fish", "Rarity" -> "unicorn") - val hm2 = (new HashMap[String,String]) ++= arm2 - - List(null, "cod", "sparrow", "Rarity").forall(i => - arm2.get(i) == hm2.get(i) && - arm2.getOrElse(i, "") == hm2.getOrElse(i, "") && - arm2(i) == hm2.get(i).getOrElse(if (i==null) "null" else i.toString) && - arm2.getOrNull(i) == hm2.get(i).orNull - ) - } -} - diff --git a/test/files/run/mutable-longmap.scala b/test/files/run/mutable-longmap.scala deleted file mode 100644 index 07fd80f6f0..0000000000 --- a/test/files/run/mutable-longmap.scala +++ /dev/null @@ -1,79 +0,0 @@ -object Test extends App { - - import scala.collection.mutable.HashMap; - import scala.collection.mutable.LongMap; - - val keys = Array( - Long.MinValue, Int.MinValue - 1L, Int.MinValue, -9127, -1, - 0, 1, 9127, Int.MaxValue, Long.MaxValue - ) - - val rn = new scala.util.Random(42L) - var lm = LongMap.empty[Long] - val hm = HashMap.empty[Long,Long] - - def checkConsistent = hm.forall{ case (k,v) => lm.get(k).exists(_ == v) } - - assert { - (0 to 10000).forall{ i => - val k = keys(rn.nextInt(keys.length)) - if (rn.nextInt(100) < 2) lm = lm.clone() - if (rn.nextInt(100) < 5) lm.repack() - if (rn.nextBoolean) { - hm += ((k, i)) - rn.nextInt(6) match { - case 0 => lm += ((k, i)) - case 1 => lm += (k, i) - case 2 => lm(k) = i - case 3 => lm.put(k,i) - case 4 => lm ++= List((k,i)) - case _ => if (!lm.contains(k)) lm.getOrElseUpdate(k,i) - else lm += (k,i) - } - } - else { - hm -= k - rn.nextInt(2) match { - case 0 => lm -= k - case _ => lm --= List(k) - } - } - checkConsistent - } - } - - assert { - lm.map{ case (k,v) => -k*k -> v.toString }.getClass == lm.getClass - } - - assert { - val lm2 = new LongMap[Unit](2000000) - for (i <- 0 until 1000000) lm2(i) = () - - lm2.size == 1000000 && - (0 to 1100000 by 100000).forall(i => (lm2 contains i) == i < 1000000) - } - - lm = LongMap(8L -> 22L, -5L -> 5L, Long.MinValue -> 0L) - - assert{ var s = 0L; lm.foreachKey(s += _); s == Long.MinValue + 3 } - assert{ var s = 0L; lm.foreachValue(s += _); s == 27L } - assert { - val m2 = lm.mapValuesNow(_+2) - lm.transformValues(_+2) - m2 == lm && !(m2 eq lm) && (for ((_,v) <- lm) yield v).sum == 33L - } - - assert { - val lm2 = new LongMap[String](_.toString) - lm2 += (5L -> "fish", 0L -> "unicorn") - val hm2 = (new HashMap[Long,String]) ++= lm2 - - List(Long.MinValue, 0L, 1L, 5L).forall(i => - lm2.get(i) == hm2.get(i) && - lm2.getOrElse(i, "") == hm2.getOrElse(i, "") && - lm2(i) == hm2.get(i).getOrElse(i.toString) && - lm2.getOrNull(i) == hm2.get(i).orNull - ) - } -} diff --git a/test/files/run/reflection-mem-typecheck.scala b/test/files/run/reflection-mem-typecheck.scala index a312c2c893..e3cabf689d 100644 --- a/test/files/run/reflection-mem-typecheck.scala +++ b/test/files/run/reflection-mem-typecheck.scala @@ -21,6 +21,6 @@ object Test extends MemoryTest { foo(List(new A {}, new B {})) """.trim snippet = snippet + "\n" + (List.fill(50)(snippet.split("\n").last) mkString "\n") - tb.typeCheck(tb.parse(snippet)) + tb.typecheck(tb.parse(snippet)) } }
\ No newline at end of file diff --git a/test/files/run/reify_ann1a.scala b/test/files/run/reify_ann1a.scala index c23048e463..e3ff9e532d 100644 --- a/test/files/run/reify_ann1a.scala +++ b/test/files/run/reify_ann1a.scala @@ -20,7 +20,7 @@ object Test extends App { // test 2: import and typecheck val toolbox = cm.mkToolBox() - val ttree = toolbox.typeCheck(tree) + val ttree = toolbox.typecheck(tree) println(ttree.toString) // test 3: import and compile diff --git a/test/files/run/reify_ann1b.scala b/test/files/run/reify_ann1b.scala index 29ce6021a2..30bafadf75 100644 --- a/test/files/run/reify_ann1b.scala +++ b/test/files/run/reify_ann1b.scala @@ -20,7 +20,7 @@ object Test extends App { // test 2: import and typecheck val toolbox = cm.mkToolBox() - val ttree = toolbox.typeCheck(tree) + val ttree = toolbox.typecheck(tree) println(ttree.toString) // test 3: import and compile diff --git a/test/files/run/reify_ann2a.scala b/test/files/run/reify_ann2a.scala index 53423e12c3..515fba015f 100644 --- a/test/files/run/reify_ann2a.scala +++ b/test/files/run/reify_ann2a.scala @@ -20,7 +20,7 @@ object Test extends App { // test 2: import and typecheck val toolbox = cm.mkToolBox() - val ttree = toolbox.typeCheck(tree) + val ttree = toolbox.typecheck(tree) println(ttree.toString) // test 3: import and compile diff --git a/test/files/run/reify_ann3.scala b/test/files/run/reify_ann3.scala index 4162fa532f..7098e928a7 100644 --- a/test/files/run/reify_ann3.scala +++ b/test/files/run/reify_ann3.scala @@ -14,7 +14,7 @@ object Test extends App { // test 2: import and typecheck val toolbox = cm.mkToolBox() - val ttree = toolbox.typeCheck(tree) + val ttree = toolbox.typecheck(tree) println(ttree.toString) // test 3: import and compile diff --git a/test/files/run/reify_ann4.scala b/test/files/run/reify_ann4.scala index 0aedb77b5e..f6426213df 100644 --- a/test/files/run/reify_ann4.scala +++ b/test/files/run/reify_ann4.scala @@ -18,7 +18,7 @@ object Test extends App { // test 2: import and typecheck val toolbox = cm.mkToolBox() - val ttree = toolbox.typeCheck(tree) + val ttree = toolbox.typecheck(tree) println(ttree.toString) // test 3: import and compile diff --git a/test/files/run/reify_ann5.scala b/test/files/run/reify_ann5.scala index d27be3b6d5..5e2f058a39 100644 --- a/test/files/run/reify_ann5.scala +++ b/test/files/run/reify_ann5.scala @@ -15,7 +15,7 @@ object Test extends App { // test 2: import and typecheck val toolbox = cm.mkToolBox() - val ttree = toolbox.typeCheck(tree) + val ttree = toolbox.typecheck(tree) println(ttree.toString) // test 3: import and compile diff --git a/test/files/run/reify_classfileann_a.scala b/test/files/run/reify_classfileann_a.scala index 1d51688e78..9ae12bff82 100644 --- a/test/files/run/reify_classfileann_a.scala +++ b/test/files/run/reify_classfileann_a.scala @@ -14,7 +14,7 @@ object Test extends App { // test 2: import and typecheck val toolbox = cm.mkToolBox() - val ttree = toolbox.typeCheck(tree) + val ttree = toolbox.typecheck(tree) println(ttree.toString) // test 3: import and compile diff --git a/test/files/run/reify_classfileann_b.scala b/test/files/run/reify_classfileann_b.scala index ef19e9240b..a0cb8f0b49 100644 --- a/test/files/run/reify_classfileann_b.scala +++ b/test/files/run/reify_classfileann_b.scala @@ -18,7 +18,7 @@ object Test extends App { // test 2: import and typecheck val toolbox = cm.mkToolBox() - val ttree = toolbox.typeCheck(tree) + val ttree = toolbox.typecheck(tree) println(ttree.toString) // test 3: import and compile diff --git a/test/files/run/reify_renamed_term_si5841.check b/test/files/run/reify_renamed_term_t5841.check index 6031277b76..6031277b76 100644 --- a/test/files/run/reify_renamed_term_si5841.check +++ b/test/files/run/reify_renamed_term_t5841.check diff --git a/test/files/run/reify_renamed_term_si5841.scala b/test/files/run/reify_renamed_term_t5841.scala index ef18d650bf..ef18d650bf 100644 --- a/test/files/run/reify_renamed_term_si5841.scala +++ b/test/files/run/reify_renamed_term_t5841.scala diff --git a/test/files/run/resetattrs-this.scala b/test/files/run/resetattrs-this.scala index 2a55437273..6150a4e265 100644 --- a/test/files/run/resetattrs-this.scala +++ b/test/files/run/resetattrs-this.scala @@ -5,7 +5,7 @@ import scala.tools.reflect.ToolBox object Test extends App { val tb = cm.mkToolBox() val tree = Select(This(cm.staticPackage("scala").moduleClass), TermName("Predef")) - val ttree = tb.typeCheck(tree) + val ttree = tb.typecheck(tree) val rttree = tb.resetAllAttrs(ttree) println(tb.eval(rttree) == Predef) } diff --git a/test/files/run/showraw_aliases.scala b/test/files/run/showraw_aliases.scala index 65b4fcb1cd..56bd13707d 100644 --- a/test/files/run/showraw_aliases.scala +++ b/test/files/run/showraw_aliases.scala @@ -7,7 +7,7 @@ object Test extends App { import scala.reflect.runtime.{universe => ru} ru """) - val ttree = tb.typeCheck(tree) + val ttree = tb.typecheck(tree) def stabilizeIds(s: String) = """#\d+""".r.replaceAllIn(s, "#<id>") def stabilizePositions(s: String) = """\d+""".r.replaceAllIn(s, "<offset>") diff --git a/test/files/run/showraw_tree_types_ids.scala b/test/files/run/showraw_tree_types_ids.scala index 198729e705..883af0110a 100644 --- a/test/files/run/showraw_tree_types_ids.scala +++ b/test/files/run/showraw_tree_types_ids.scala @@ -6,6 +6,6 @@ object Test extends App { val tree1 = reify(new collection.immutable.HashMap[String, String]) val tree2 = reify(new collection.mutable.HashMap[String, String]) def stabilize(s: String) = """#\d+""".r.replaceAllIn(s, "#<id>") - println(stabilize(showRaw(tb.typeCheck(tree1.tree), printIds = true, printTypes = true))) - println(stabilize(showRaw(tb.typeCheck(tree2.tree), printIds = true, printTypes = true))) + println(stabilize(showRaw(tb.typecheck(tree1.tree), printIds = true, printTypes = true))) + println(stabilize(showRaw(tb.typecheck(tree2.tree), printIds = true, printTypes = true))) }
\ No newline at end of file diff --git a/test/files/run/showraw_tree_types_typed.scala b/test/files/run/showraw_tree_types_typed.scala index d7ccc84ea3..3dd696c77e 100644 --- a/test/files/run/showraw_tree_types_typed.scala +++ b/test/files/run/showraw_tree_types_typed.scala @@ -5,6 +5,6 @@ object Test extends App { val tb = runtimeMirror(getClass.getClassLoader).mkToolBox() val tree1 = reify(new collection.immutable.HashMap[String, String]) val tree2 = reify(new collection.mutable.HashMap[String, String]) - println(showRaw(tb.typeCheck(tree1.tree), printTypes = true)) - println(showRaw(tb.typeCheck(tree2.tree), printTypes = true)) + println(showRaw(tb.typecheck(tree1.tree), printTypes = true)) + println(showRaw(tb.typecheck(tree2.tree), printTypes = true)) }
\ No newline at end of file diff --git a/test/files/run/showraw_tree_ultimate.scala b/test/files/run/showraw_tree_ultimate.scala index a8507623bc..e0d36e6bb7 100644 --- a/test/files/run/showraw_tree_ultimate.scala +++ b/test/files/run/showraw_tree_ultimate.scala @@ -6,6 +6,6 @@ object Test extends App { val tree1 = reify(new collection.immutable.HashMap[String, String]) val tree2 = reify(new collection.mutable.HashMap[String, String]) def stabilize(s: String) = """#\d+""".r.replaceAllIn(s, "#<id>") - println(stabilize(showRaw(tb.typeCheck(tree1.tree), printIds = true, printKinds = true, printTypes = true))) - println(stabilize(showRaw(tb.typeCheck(tree2.tree), printIds = true, printKinds = true, printTypes = true))) + println(stabilize(showRaw(tb.typecheck(tree1.tree), printIds = true, printKinds = true, printTypes = true))) + println(stabilize(showRaw(tb.typecheck(tree2.tree), printIds = true, printKinds = true, printTypes = true))) }
\ No newline at end of file diff --git a/test/files/run/si4750.check b/test/files/run/t4750.check index bf55f70df3..bf55f70df3 100644 --- a/test/files/run/si4750.check +++ b/test/files/run/t4750.check diff --git a/test/files/run/si4750.scala b/test/files/run/t4750.scala index 96d2c4fec7..96d2c4fec7 100644 --- a/test/files/run/si4750.scala +++ b/test/files/run/t4750.scala diff --git a/test/files/run/si5045.check b/test/files/run/t5045.check index 7e9c1961b7..7e9c1961b7 100644 --- a/test/files/run/si5045.check +++ b/test/files/run/t5045.check diff --git a/test/files/run/si5045.scala b/test/files/run/t5045.scala index b0c3a4ddc4..b0c3a4ddc4 100644 --- a/test/files/run/si5045.scala +++ b/test/files/run/t5045.scala diff --git a/test/files/run/t5415.scala b/test/files/run/t5415.scala index c12e209bb7..65de86245b 100644 --- a/test/files/run/t5415.scala +++ b/test/files/run/t5415.scala @@ -8,5 +8,5 @@ object Test extends App{ import scala.reflect.runtime.{currentMirror => cm} import scala.tools.reflect.ToolBox val toolbox = cm.mkToolBox() - val ttree = toolbox.typeCheck(code.tree) + val ttree = toolbox.typecheck(code.tree) } diff --git a/test/files/run/t5418b.scala b/test/files/run/t5418b.scala index 08e8bb163b..c6172613d5 100644 --- a/test/files/run/t5418b.scala +++ b/test/files/run/t5418b.scala @@ -5,7 +5,7 @@ import scala.tools.reflect.ToolBox object Test extends App { val tb = cm.mkToolBox() val untyped = reify(new Object().getClass).tree - val typed = tb.typeCheck(untyped) + val typed = tb.typecheck(untyped) println(typed) println(showRaw(typed.tpe)) }
\ No newline at end of file diff --git a/test/files/run/t5704.scala b/test/files/run/t5704.scala index ddcbcc27b3..495a82e4f0 100644 --- a/test/files/run/t5704.scala +++ b/test/files/run/t5704.scala @@ -8,7 +8,7 @@ object Test extends App { def findUserByName( name:String ) = { val tree = reify{ "test" == name }.tree val toolbox = cm.mkToolBox() - toolbox.typeCheck(tree) match{ + toolbox.typecheck(tree) match{ case Apply(Select(lhs,op),rhs::Nil) => println(rhs.tpe) } diff --git a/test/files/run/t5816.scala b/test/files/run/t5816.scala index f0279e5703..e8367ea81e 100644 --- a/test/files/run/t5816.scala +++ b/test/files/run/t5816.scala @@ -6,7 +6,7 @@ object Test extends App { val toolbox = cm.mkToolBox() def printSource[T](expr: Expr[T]) { - val ttree = toolbox typeCheck expr.tree + val ttree = toolbox typecheck expr.tree println(ttree.toString) } diff --git a/test/files/run/t5912.scala b/test/files/run/t5912.scala index 9418e946d0..fc879a0537 100644 --- a/test/files/run/t5912.scala +++ b/test/files/run/t5912.scala @@ -3,5 +3,5 @@ object Test extends App{ import scala.reflect.runtime.{currentMirror=>cm} import scala.tools.reflect._ import scala.reflect.runtime.universe._ - val tree = cm.mkToolBox().typeCheck( Literal(Constant("test")) ) + val tree = cm.mkToolBox().typecheck( Literal(Constant("test")) ) } diff --git a/test/files/run/t5943a1.scala b/test/files/run/t5943a1.scala index 00f4afa808..6bb828de85 100644 --- a/test/files/run/t5943a1.scala +++ b/test/files/run/t5943a1.scala @@ -5,5 +5,5 @@ import scala.tools.reflect.ToolBox object Test extends App { val tb = cm.mkToolBox() val expr = tb.parse("1 to 3 map (_+1)") - println(tb.typeCheck(expr)) + println(tb.typecheck(expr)) }
\ No newline at end of file diff --git a/test/files/run/t6023.scala b/test/files/run/t6023.scala index 07af3685a5..2753b93ac4 100644 --- a/test/files/run/t6023.scala +++ b/test/files/run/t6023.scala @@ -9,7 +9,7 @@ object Test extends App { // test 2: import and typecheck val toolbox = cm.mkToolBox() - val ttree = toolbox.typeCheck(tree) + val ttree = toolbox.typecheck(tree) println(ttree.toString) // test 3: import and compile diff --git a/test/files/run/t6355.check b/test/files/run/t6355.check new file mode 100644 index 0000000000..ce74ab38a2 --- /dev/null +++ b/test/files/run/t6355.check @@ -0,0 +1,2 @@ +bippy(x: Int) called with x = 42 +bippy(x: String) called with x = "42" diff --git a/test/files/run/t6355.scala b/test/files/run/t6355.scala new file mode 100644 index 0000000000..f1921391a3 --- /dev/null +++ b/test/files/run/t6355.scala @@ -0,0 +1,17 @@ +import scala.language.dynamics + +class A extends Dynamic { + def applyDynamic(method: String): B = new B(method) +} +class B(method: String) { + def apply(x: Int) = s"$method(x: Int) called with x = $x" + def apply(x: String) = s"""$method(x: String) called with x = "$x"""" +} + +object Test { + def main(args: Array[String]): Unit = { + val x = new A + println(x.bippy(42)) + println(x.bippy("42")) + } +} diff --git a/test/files/run/t6392b.scala b/test/files/run/t6392b.scala index f69a5aaf45..e43c1a2b03 100644 --- a/test/files/run/t6392b.scala +++ b/test/files/run/t6392b.scala @@ -5,5 +5,5 @@ import scala.tools.reflect.ToolBox object Test extends App { val tb = cm.mkToolBox() val c = tb.parse("object C") - println(showRaw(tb.typeCheck(c), printKinds = true)) + println(showRaw(tb.typecheck(c), printKinds = true)) }
\ No newline at end of file diff --git a/test/files/run/t7185.check b/test/files/run/t7185.check index 38449b3497..ebf85b731f 100644 --- a/test/files/run/t7185.check +++ b/test/files/run/t7185.check @@ -21,7 +21,7 @@ tree: reflect.runtime.universe.Apply = } }() -scala> {val tb = reflect.runtime.currentMirror.mkToolBox(); tb.typeCheck(tree): Any} +scala> {val tb = reflect.runtime.currentMirror.mkToolBox(); tb.typecheck(tree): Any} res0: Any = { { diff --git a/test/files/run/t7185.scala b/test/files/run/t7185.scala index d9d913e78a..62d64246bc 100644 --- a/test/files/run/t7185.scala +++ b/test/files/run/t7185.scala @@ -7,6 +7,6 @@ import scala.reflect.runtime.universe._ object O { def apply() = 0 } val ORef = reify { O }.tree val tree = Apply(Block(Nil, Block(Nil, ORef)), Nil) -{val tb = reflect.runtime.currentMirror.mkToolBox(); tb.typeCheck(tree): Any} +{val tb = reflect.runtime.currentMirror.mkToolBox(); tb.typecheck(tree): Any} """ } diff --git a/test/files/run/t7406.check b/test/files/run/t7406.check new file mode 100644 index 0000000000..f599e28b8a --- /dev/null +++ b/test/files/run/t7406.check @@ -0,0 +1 @@ +10 diff --git a/test/files/run/t7406.scala b/test/files/run/t7406.scala new file mode 100644 index 0000000000..a8b35c91c9 --- /dev/null +++ b/test/files/run/t7406.scala @@ -0,0 +1,14 @@ +class Arne[@specialized(Long) T](x: T) { + val regularVal = x + lazy val lazyVal = x + + def apply(f: (T, T) => T): T = f(regularVal, lazyVal) +} + +object Test { + val arne = new Arne(5L) + def f = arne(_ + _) + def main(args: Array[String]): Unit = { + println(f) + } +} diff --git a/test/files/run/t7777.check b/test/files/run/t7777.check new file mode 100644 index 0000000000..162ff2d2a2 --- /dev/null +++ b/test/files/run/t7777.check @@ -0,0 +1,7 @@ +foo(1, 2) +bar(4, 5) +foo(3) +bar(7) +apply(6) +apply(9) +foo(8) diff --git a/test/files/run/t7777/Macros_1.scala b/test/files/run/t7777/Macros_1.scala new file mode 100644 index 0000000000..459ab3edbb --- /dev/null +++ b/test/files/run/t7777/Macros_1.scala @@ -0,0 +1,17 @@ +import scala.language.experimental.macros +import scala.language.dynamics +import scala.reflect.macros.WhiteboxContext + +class DynMacro extends Dynamic { + def applyDynamic(s: String)(xs: Any*): DynMacro = + macro DynMacro.applyDynamicMacro +} + +object DynMacro extends DynMacro { + def applyDynamicMacro(c: WhiteboxContext)(s: c.Expr[String])(xs: c.Expr[Any]*): c.Expr[DynMacro] = { + import c.universe._ + val Literal(Constant(n: String)) = s.tree + val args = xs.map(_.tree.toString).mkString("(", ", ", ")") + c.Expr(q"println(${ n + args }); ${c.prefix.tree}") + } +}
\ No newline at end of file diff --git a/test/files/run/t7777/Test_2.scala b/test/files/run/t7777/Test_2.scala new file mode 100644 index 0000000000..1fe8b63bab --- /dev/null +++ b/test/files/run/t7777/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + DynMacro.foo(1, 2) // prints "foo(1, 2)" + DynMacro.foo(3).bar(4, 5) // prints "bar(4, 5)", then "foo(3)" + DynMacro(6).bar(7) // prints "bar(7)", then "apply(6)" + DynMacro.foo(8)(9) // Fails! +}
\ No newline at end of file diff --git a/test/files/run/t7880.scala b/test/files/run/t7880.scala new file mode 100644 index 0000000000..9fbc337f87 --- /dev/null +++ b/test/files/run/t7880.scala @@ -0,0 +1,7 @@ +object Test extends App { + // This should terminate in one way or another, but it shouldn't loop forever. + try { + val buffer = collection.mutable.ArrayBuffer.fill(Int.MaxValue / 2 + 1)(0) + buffer append 1 + } catch { case _: OutOfMemoryError => } +} diff --git a/test/files/run/t8017.flags b/test/files/run/t8017.flags new file mode 100644 index 0000000000..48b438ddf8 --- /dev/null +++ b/test/files/run/t8017.flags @@ -0,0 +1 @@ +-Ydelambdafy:method diff --git a/test/files/run/t8017/value-class-lambda.scala b/test/files/run/t8017/value-class-lambda.scala new file mode 100644 index 0000000000..370023b194 --- /dev/null +++ b/test/files/run/t8017/value-class-lambda.scala @@ -0,0 +1,40 @@ +object Test { + def testC { + val f1 = (c: C) => c.value + val f2 = (x: Int) => new C(x) + val f3 = (c1: C) => (c2: C) => (c1, c2) + val r1 = f2(2) + val r2 = f2(2) + val r3 = f3(r1)(r2) + val result = f1(r3._2) + assert(result == 2) + } + + def testD { + val f1 = (c: D) => c.value + val f2 = (x: String) => new D(x) + val f3 = (c1: D) => (c2: D) => (c1, c2) + val r1 = f2("2") + val r2 = f2("2") + val r3 = f3(r1)(r2) + val result = f1(r3._2) + assert(result == "2") + } + + def testE { + val f1 = (c: E[Int]) => c.value + val f2 = (x: Int) => new E(x) + val f3 = (c1: E[Int]) => (c2: E[Int]) => (c1, c2) + val r1 = f2(2) + val r2 = f2(2) + val r3 = f3(r1)(r2) + val result = f1(r3._2) + assert(result == 2) + } + + def main(args: Array[String]) { + testC + testD + testE + } +} diff --git a/test/files/run/t8017/value-class.scala b/test/files/run/t8017/value-class.scala new file mode 100644 index 0000000000..821239305f --- /dev/null +++ b/test/files/run/t8017/value-class.scala @@ -0,0 +1,3 @@ +class C(val value: Int) extends AnyVal +class D(val value: String) extends AnyVal +class E[A](val value: A) extends AnyVal diff --git a/test/files/run/t8047.check b/test/files/run/t8047.check new file mode 100644 index 0000000000..a6b83a4a16 --- /dev/null +++ b/test/files/run/t8047.check @@ -0,0 +1,7 @@ +doWhile$1(){ + 1; + if (true) + doWhile$1() + else + () +} diff --git a/test/files/run/t8047.scala b/test/files/run/t8047.scala new file mode 100644 index 0000000000..f5660541e8 --- /dev/null +++ b/test/files/run/t8047.scala @@ -0,0 +1,31 @@ +object Test extends App { + import scala.reflect.runtime.universe._ + // + // x's owner is outer Test scope. Previosly the quasiquote expansion + // looked like: + // + // object Test { + // build.withFreshTermName("doWhile")(n => + // LabelDef(n, List(), + // Block( + // List({ val x = 1; x }), + // If(Literal(Constant(true)), Apply(Ident(n), List()), Literal(Constant(()))))) + // } + // + // Here the proper owner is anonymous function, not the Test. Hence + // symbol corruption. In new encoding this is represented as: + // + // object Test { + // { + // val n = build.freshTermName("doWhile") + // LabelDef(n, List(), + // Block( + // List({ val x = 1; x }), + // If(Literal(Constant(true)), Apply(Ident(n), List()), Literal(Constant(())))) + // } + // } + // + // Owner stays the same and life is good again. + // + println(q"do ${ val x = 1; x } while(true)") +} diff --git a/test/files/run/t8091.check b/test/files/run/t8091.check new file mode 100644 index 0000000000..4c4e91774f --- /dev/null +++ b/test/files/run/t8091.check @@ -0,0 +1 @@ +börk börk diff --git a/test/files/run/t8091.scala b/test/files/run/t8091.scala new file mode 100644 index 0000000000..cd412d4c2a --- /dev/null +++ b/test/files/run/t8091.scala @@ -0,0 +1,4 @@ +object Test extends App { + val result = "börk börk" flatMap (ch ⇒ if (ch > 127) f"&#x${ch}%04x;" else "" + ch) + println(result) +}
\ No newline at end of file diff --git a/test/files/run/t8104.check b/test/files/run/t8104.check new file mode 100644 index 0000000000..c2593eb199 --- /dev/null +++ b/test/files/run/t8104.check @@ -0,0 +1 @@ +TypeTag[(Int, Int)] diff --git a/test/files/run/t8104/Macros_1.scala b/test/files/run/t8104/Macros_1.scala new file mode 100644 index 0000000000..21d81a3687 --- /dev/null +++ b/test/files/run/t8104/Macros_1.scala @@ -0,0 +1,11 @@ +import scala.reflect.macros.WhiteboxContext + +object Macros { + def impl[T](c: WhiteboxContext)(implicit T: c.WeakTypeTag[T]) = { + import c.universe._ + import definitions._ + val fields = T.tpe.declarations.toList.collect{ case x: TermSymbol if x.isVal && x.isCaseAccessor => x } + val Repr = appliedType(TupleClass(fields.length).asType.toType, fields.map(_.typeSignature)) + q"new Generic[$T]{ type Repr = $Repr }" + } +}
\ No newline at end of file diff --git a/test/files/run/t8104/Test_2.scala b/test/files/run/t8104/Test_2.scala new file mode 100644 index 0000000000..630176f175 --- /dev/null +++ b/test/files/run/t8104/Test_2.scala @@ -0,0 +1,16 @@ +trait Generic[T] { type Repr } +object Generic { + type Aux[T, Repr0] = Generic[T] { type Repr = Repr0 } + import scala.language.experimental.macros + implicit def materializeGeneric[T, Repr]: Generic.Aux[T, Repr] = macro Macros.impl[T] +} + +object Test extends App { + case class C(x: Int, y: Int) + + import scala.reflect.runtime.universe._ + def reprify[T, Repr](x: T)(implicit generic: Generic.Aux[T, Repr], tag: TypeTag[Repr]) = println(tag) + reprify(C(40, 2)) + + implicitly[Generic.Aux[C, (Int, Int)]] +} diff --git a/test/files/run/toolbox_typecheck_implicitsdisabled.scala b/test/files/run/toolbox_typecheck_implicitsdisabled.scala index 95a7056279..8c1a6e580c 100644 --- a/test/files/run/toolbox_typecheck_implicitsdisabled.scala +++ b/test/files/run/toolbox_typecheck_implicitsdisabled.scala @@ -10,7 +10,7 @@ object Test extends App { Import(Select(Ident(TermName("scala")), TermName("Predef")), List(ImportSelector(nme.WILDCARD, -1, null, -1)))), Apply(Select(Literal(Constant(1)), TermName("$minus$greater")), List(Literal(Constant(2)))) ) - val ttree1 = toolbox.typeCheck(tree1, withImplicitViewsDisabled = false) + val ttree1 = toolbox.typecheck(tree1, withImplicitViewsDisabled = false) println(ttree1) try { @@ -18,7 +18,7 @@ object Test extends App { Import(Select(Ident(TermName("scala")), TermName("Predef")), List(ImportSelector(nme.WILDCARD, -1, null, -1)))), Apply(Select(Literal(Constant(1)), TermName("$minus$greater")), List(Literal(Constant(2)))) ) - val ttree2 = toolbox.typeCheck(tree2, withImplicitViewsDisabled = true) + val ttree2 = toolbox.typecheck(tree2, withImplicitViewsDisabled = true) println(ttree2) } catch { case ex: Throwable => diff --git a/test/files/run/toolbox_typecheck_macrosdisabled.check b/test/files/run/toolbox_typecheck_macrosdisabled.check index 3de296f1ad..d9e79cdd19 100644 --- a/test/files/run/toolbox_typecheck_macrosdisabled.check +++ b/test/files/run/toolbox_typecheck_macrosdisabled.check @@ -1,4 +1,4 @@ -{ +({ val $u: ru.type = ru; val $m: $u.Mirror = ru.runtimeMirror({ final class $anon extends scala.AnyRef { @@ -37,5 +37,5 @@ }; new $typecreator2() })) -} +}: ru.Expr[Int]) ru.reify[Int](2) diff --git a/test/files/run/toolbox_typecheck_macrosdisabled.scala b/test/files/run/toolbox_typecheck_macrosdisabled.scala index 1f7fda8575..4cbeefd6e0 100644 --- a/test/files/run/toolbox_typecheck_macrosdisabled.scala +++ b/test/files/run/toolbox_typecheck_macrosdisabled.scala @@ -16,10 +16,10 @@ object Test extends App { build.setTypeSignature(ru, rutpe) val tree1 = Apply(Select(Ident(ru), TermName("reify")), List(Literal(Constant(2)))) - val ttree1 = toolbox.typeCheck(tree1, withMacrosDisabled = false) + val ttree1 = toolbox.typecheck(tree1, withMacrosDisabled = false) println(ttree1) val tree2 = Apply(Select(Ident(ru), TermName("reify")), List(Literal(Constant(2)))) - val ttree2 = toolbox.typeCheck(tree2, withMacrosDisabled = true) + val ttree2 = toolbox.typecheck(tree2, withMacrosDisabled = true) println(ttree2) } diff --git a/test/files/run/toolbox_typecheck_macrosdisabled2.check b/test/files/run/toolbox_typecheck_macrosdisabled2.check index 9810946024..8e554a6c8f 100644 --- a/test/files/run/toolbox_typecheck_macrosdisabled2.check +++ b/test/files/run/toolbox_typecheck_macrosdisabled2.check @@ -1,4 +1,4 @@ -{ +({ val $u: ru.type = ru; val $m: $u.Mirror = ru.runtimeMirror({ final class $anon extends scala.AnyRef { @@ -37,5 +37,5 @@ }; new $typecreator2() })) -} +}: ru.Expr[Array[Int]]) ru.reify[Array[Int]](scala.Array.apply(2)) diff --git a/test/files/run/toolbox_typecheck_macrosdisabled2.scala b/test/files/run/toolbox_typecheck_macrosdisabled2.scala index 7bfe3ba8a4..2fbd8f7c7a 100644 --- a/test/files/run/toolbox_typecheck_macrosdisabled2.scala +++ b/test/files/run/toolbox_typecheck_macrosdisabled2.scala @@ -16,10 +16,10 @@ object Test extends App { build.setTypeSignature(ru, rutpe) val tree1 = Apply(Select(Ident(ru), TermName("reify")), List(Apply(Select(Ident(TermName("scala")), TermName("Array")), List(Literal(Constant(2)))))) - val ttree1 = toolbox.typeCheck(tree1, withMacrosDisabled = false) + val ttree1 = toolbox.typecheck(tree1, withMacrosDisabled = false) println(ttree1) val tree2 = Apply(Select(Ident(ru), TermName("reify")), List(Apply(Select(Ident(TermName("scala")), TermName("Array")), List(Literal(Constant(2)))))) - val ttree2 = toolbox.typeCheck(tree2, withMacrosDisabled = true) + val ttree2 = toolbox.typecheck(tree2, withMacrosDisabled = true) println(ttree2) } diff --git a/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala b/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala index 5411e664a2..e4ee5dfcae 100644 --- a/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala +++ b/test/files/scalacheck/quasiquotes/QuasiquoteProperties.scala @@ -81,7 +81,7 @@ trait Helpers { val compile = toolbox.compile(_) val eval = toolbox.eval(_) - def typecheck(tree: Tree) = toolbox.typeCheck(tree) + def typecheck(tree: Tree) = toolbox.typecheck(tree) def typecheckTyp(tree: Tree) = { val q"type $_ = $res" = typecheck(q"type T = $tree") diff --git a/test/files/scalacheck/si4147.scala b/test/files/scalacheck/t4147.scala index 72f6e9afd5..72f6e9afd5 100644 --- a/test/files/scalacheck/si4147.scala +++ b/test/files/scalacheck/t4147.scala diff --git a/test/junit/scala/collection/ArraySortingTest.scala b/test/junit/scala/collection/ArraySortingTest.scala new file mode 100644 index 0000000000..4e54b39ce7 --- /dev/null +++ b/test/junit/scala/collection/ArraySortingTest.scala @@ -0,0 +1,29 @@ +package scala.collection.mutable + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test + +/* Tests various maps by making sure they all agree on the same answers. */ +@RunWith(classOf[JUnit4]) +class ArraySortingTest { + + class CantSortMe(val i: Int) { + override def equals(a: Any) = throw new IllegalArgumentException("I cannot be equalled!") + } + + object CanOrder extends Ordering[CantSortMe] { + def compare(a: CantSortMe, b: CantSortMe) = a.i compare b.i + } + + // Tests SI-7837 + @Test + def sortByTest() { + val test = Array(1,2,3,4,1,3,5,7,1,4,8,1,1,1,1) + val cant = test.map(i => new CantSortMe(i)) + java.util.Arrays.sort(test) + scala.util.Sorting.quickSort(cant)(CanOrder) + assert( test(6) == 1 ) + assert( (test,cant).zipped.forall(_ == _.i) ) + } +} diff --git a/test/junit/scala/collection/SetMapConsistencyTest.scala b/test/junit/scala/collection/SetMapConsistencyTest.scala new file mode 100644 index 0000000000..c62b074483 --- /dev/null +++ b/test/junit/scala/collection/SetMapConsistencyTest.scala @@ -0,0 +1,479 @@ +package scala.collection + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test +import scala.collection.{mutable => cm, immutable => ci} +import scala.collection.JavaConverters._ + +/* Tests various maps by making sure they all agree on the same answers. */ +@RunWith(classOf[JUnit4]) +class SetMapConsistencyTest { + + trait MapBox[A] { + protected def oor(s: String, n: Int) = throw new IllegalArgumentException(s"Out of range for $s: $n") + def title: String + def adders: Int + def add(n: Int, a: A, v: Int): Unit + def subbers: Int + def sub(n: Int, a: A): Unit + def getters: Int + def get(n: Int, a: A): Int + def fiddlers: Int + def fiddle(n: Int): Unit + def keys: Iterator[A] + def has(a: A): Boolean + } + + + // Mutable map wrappers + + class BoxMutableMap[A, M <: cm.Map[A, Int]](m0: M, title0: String) extends MapBox[A] { + var m = m0 + def title = title0 + def adders = 5 + def add(n: Int, a: A, v: Int) { n match { + case 0 => m += ((a, v)) + case 1 => m(a) = v + case 2 => m.put(a, v) + case 3 => m = (m + ((a, v))).asInstanceOf[M] + case 4 => m = (m ++ List((a, v))).asInstanceOf[M] + case _ => oor("add", n) + }} + def subbers: Int = 3 + def sub(n: Int, a: A) { n match { + case 0 => m -= a + case 1 => m = (m - a).asInstanceOf[M] + case 2 => m = m.filter(_._1 != a).asInstanceOf[M] + case _ => oor("sub", n) + }} + def getters: Int = 3 + def get(n: Int, a: A) = n match { + case 0 => m.get(a).getOrElse(-1) + case 1 => if (m contains a) m(a) else -1 + case 2 => m.getOrElse(a, -1) + case _ => oor("get", n) + } + def fiddlers: Int = 0 + def fiddle(n: Int) { oor("fiddle", n) } + def keys = m.keysIterator + def has(a: A) = m contains a + override def toString = m.toString + } + + def boxMlm[A] = new BoxMutableMap[A, cm.ListMap[A, Int]](new cm.ListMap[A, Int], "mutable.ListMap") + + def boxMhm[A] = new BoxMutableMap[A, cm.HashMap[A, Int]](new cm.HashMap[A, Int], "mutable.HashMap") + + def boxMohm[A] = new BoxMutableMap[A, cm.OpenHashMap[A, Int]](new cm.OpenHashMap[A, Int], "mutable.OpenHashMap") + + def boxMarm[A <: AnyRef] = new BoxMutableMap[A, cm.AnyRefMap[A, Int]](new cm.AnyRefMap[A, Int](_ => -1), "mutable.AnyRefMap") { + private def arm: cm.AnyRefMap[A, Int] = m.asInstanceOf[cm.AnyRefMap[A, Int]] + override def adders = 3 + override def subbers = 1 + override def getters: Int = 4 + override def get(n: Int, a: A) = n match { + case 0 => m.get(a).getOrElse(-1) + case 1 => m(a) + case 2 => m.getOrElse(a, -1) + case 3 => val x = arm.getOrNull(a); if (x==0 && !(arm contains a)) -1 else x + case _ => oor("get", n) + } + override def fiddlers = 2 + override def fiddle(n: Int) { n match { + case 0 => m = arm.clone + case 1 => arm.repack + case _ => oor("fiddle", n) + }} + } + + def boxMjm = new BoxMutableMap[Long, cm.LongMap[Int]](new cm.LongMap[Int](_ => -1), "mutable.LongMap") { + private def lm: cm.LongMap[Int] = m.asInstanceOf[cm.LongMap[Int]] + override def adders = 3 + override def subbers = 1 + override def getters: Int = 4 + override def get(n: Int, a: Long) = n match { + case 0 => m.get(a).getOrElse(-1) + case 1 => m(a) + case 2 => m.getOrElse(a, -1) + case 3 => val x = lm.getOrNull(a); if (x==0 && !(lm contains a)) -1 else x + case _ => oor("get", n) + } + override def fiddlers = 2 + override def fiddle(n: Int) { n match { + case 0 => m = lm.clone + case 1 => lm.repack + case _ => oor("fiddle", n) + }} + } + + def boxJavaM[A] = new BoxMutableMap[A, cm.Map[A, Int]]((new java.util.HashMap[A, Int]).asScala, "java.util.HashMap") { + override def adders = 3 + override def subbers = 1 + } + + + // Immutable map wrappers + + class BoxImmutableMap[A, M <: ci.Map[A, Int]](m0: M, title0: String) extends MapBox[A] { + var m = m0 + def title = title0 + def adders = 2 + def add(n: Int, a: A, v: Int) { n match { + case 0 => m = (m + ((a, v))).asInstanceOf[M] + case 1 => m = (m ++ List((a, v))).asInstanceOf[M] + case _ => oor("add", n) + }} + def subbers: Int = 2 + def sub(n: Int, a: A) { n match { + case 0 => m = (m - a).asInstanceOf[M] + case 1 => m = m.filter(_._1 != a).asInstanceOf[M] + case _ => oor("sub", n) + }} + def getters: Int = 3 + def get(n: Int, a: A) = n match { + case 0 => m.get(a).getOrElse(-1) + case 1 => if (m contains a) m(a) else -1 + case 2 => m.getOrElse(a, -1) + case _ => oor("get", n) + } + def fiddlers: Int = 0 + def fiddle(n: Int) { oor("fiddle", n) } + def keys = m.keysIterator + def has(a: A) = m contains a + override def toString = m.toString + } + + def boxIhm[A] = new BoxImmutableMap[A, ci.HashMap[A,Int]](new ci.HashMap[A, Int], "immutable.HashMap") + + def boxIim = new BoxImmutableMap[Int, ci.IntMap[Int]](ci.IntMap.empty[Int], "immutable.IntMap") + + def boxIjm = new BoxImmutableMap[Long, ci.LongMap[Int]](ci.LongMap.empty[Int], "immutable.LongMap") + + def boxIlm[A] = new BoxImmutableMap[A, ci.ListMap[A, Int]](new ci.ListMap[A, Int], "immutable.ListMap") + + def boxItm[A: Ordering] = new BoxImmutableMap[A, ci.TreeMap[A, Int]](new ci.TreeMap[A, Int], "immutable.TreeMap") + + + // Mutable set wrappers placed into the same framework (everything returns 0) + + class BoxMutableSet[A, M <: cm.Set[A]](s0: M, title0: String) extends MapBox[A] { + protected var m = s0 + def title = title0 + def adders = 5 + def add(n: Int, a: A, v: Int) { n match { + case 0 => m += a + case 1 => m(a) = true + case 2 => m add a + case 3 => m = (m + a).asInstanceOf[M] + case 4 => m = (m ++ List(a)).asInstanceOf[M] + case _ => oor("add", n) + }} + def subbers: Int = 3 + def sub(n: Int, a: A) { n match { + case 0 => m -= a + case 1 => m = (m - a).asInstanceOf[M] + case 2 => m = m.filter(_ != a).asInstanceOf[M] + case _ => oor("sub", n) + }} + def getters: Int = 1 + def get(n: Int, a: A) = if (m(a)) 0 else -1 + def fiddlers: Int = 0 + def fiddle(n: Int) { oor("fiddle", n) } + def keys = m.iterator + def has(a: A) = m(a) + override def toString = m.toString + } + + def boxMbs = new BoxMutableSet[Int, cm.BitSet](new cm.BitSet, "mutable.BitSet") + + def boxMhs[A] = new BoxMutableSet[A, cm.HashSet[A]](new cm.HashSet[A], "mutable.HashSet") + + def boxJavaS[A] = new BoxMutableSet[A, cm.Set[A]]((new java.util.HashSet[A]).asScala, "java.util.HashSet") { + override def adders = 3 + override def subbers = 1 + } + + + // Immutable set wrappers placed into the same framework (everything returns 0) + + class BoxImmutableSet[A, M <: ci.Set[A]](s0: M, title0: String) extends MapBox[A] { + protected var m = s0 + def title = title0 + def adders = 2 + def add(n: Int, a: A, v: Int) { n match { + case 0 => m = (m + a).asInstanceOf[M] + case 1 => m = (m ++ List(a)).asInstanceOf[M] + case _ => oor("add", n) + }} + def subbers: Int = 2 + def sub(n: Int, a: A) { n match { + case 0 => m = (m - a).asInstanceOf[M] + case 1 => m = m.filter(_ != a).asInstanceOf[M] + case _ => oor("sub", n) + }} + def getters: Int = 1 + def get(n: Int, a: A) = if (m(a)) 0 else -1 + def fiddlers: Int = 0 + def fiddle(n: Int) { oor("fiddle", n) } + def keys = m.iterator + def has(a: A) = m(a) + override def toString = m.toString + } + + def boxIbs = new BoxImmutableSet[Int, ci.BitSet](ci.BitSet.empty, "immutable.BitSet") + + def boxIhs[A] = new BoxImmutableSet[A, ci.HashSet[A]](ci.HashSet.empty[A], "mutable.HashSet") + + def boxIls[A] = new BoxImmutableSet[A, ci.ListSet[A]](ci.ListSet.empty[A], "mutable.ListSet") + + def boxIts[A: Ordering] = new BoxImmutableSet[A, ci.TreeSet[A]](ci.TreeSet.empty[A], "mutable.TreeSet") + + + // Random operations on maps + def churn[A](map1: MapBox[A], map2: MapBox[A], keys: Array[A], n: Int = 1000, seed: Int = 42, valuer: Int => Int = identity) = { + def check = map1.keys.forall(map2 has _) && map2.keys.forall(map1 has _) + val rn = new scala.util.Random(seed) + var what = new StringBuilder + what ++= "creation" + for (i <- 0 until n) { + if (!check) { + val temp = map2 match { + case b: BoxImmutableMap[_, _] => b.m match { + case hx: ci.HashMap.HashTrieMap[_,_] => + val h = hx.asInstanceOf[ci.HashMap.HashTrieMap[A, Int]] + Some((h.bitmap.toHexString, h.elems.mkString, h.size)) + case _ => None + } + case _ => None + } + throw new Exception(s"Disagreement after ${what.result} between ${map1.title} and ${map2.title} because ${map1.keys.map(map2 has _).mkString(",")} ${map2.keys.map(map1 has _).mkString(",")} at step $i:\n$map1\n$map2\n$temp") + } + what ++= " (%d) ".format(i) + if (rn.nextInt(10)==0) { + + if (map1.fiddlers > 0) map1.fiddle({ + val n = rn.nextInt(map1.fiddlers) + what ++= ("f"+n) + n + }) + if (map2.fiddlers > 0) map2.fiddle({ + val n = rn.nextInt(map2.fiddlers) + what ++= ("F"+n) + n + }) + } + if (rn.nextBoolean) { + val idx = rn.nextInt(keys.length) + val key = keys(rn.nextInt(keys.length)) + val n1 = rn.nextInt(map1.adders) + val n2 = rn.nextInt(map2.adders) + what ++= "+%s(%d,%d)".format(key,n1,n2) + map1.add(n1, key, valuer(idx)) + map2.add(n2, key, valuer(idx)) + } + else { + val n = rn.nextInt(keys.length) + val key = keys(n) + val n1 = rn.nextInt(map1.subbers) + val n2 = rn.nextInt(map2.subbers) + what ++= "-%s(%d,%d)".format(key, n1, n2) + //println(s"- $key") + map1.sub(n1, key) + map2.sub(n2, key) + } + val j = rn.nextInt(keys.length) + val gn1 = rn.nextInt(map1.getters) + val gn2 = rn.nextInt(map2.getters) + val g1 = map1.get(gn1, keys(j)) + val g2 = map2.get(gn2, keys(j)) + if (g1 != g2) { + val temp = map2 match { + case b: BoxImmutableMap[_, _] => b.m match { + case hx: ci.HashMap.HashTrieMap[_,_] => + val h = hx.asInstanceOf[ci.HashMap.HashTrieMap[A, Int]] + val y = (ci.HashMap.empty[A, Int] ++ h).asInstanceOf[ci.HashMap.HashTrieMap[A, Int]] + Some(((h.bitmap.toHexString, h.elems.mkString, h.size),(y.bitmap.toHexString, y.elems.mkString, y.size))) + case _ => None + } + case _ => None + } + throw new Exception(s"Disagreement after ${what.result} between ${map1.title} and ${map2.title} on get of ${keys(j)} (#$j) on step $i: $g1 != $g2 using methods $gn1 and $gn2 resp.; in full\n$map1\n$map2\n$temp") + } + } + true + } + + + // Actual tests + val smallKeys = Array(0, 1, 42, 9127) + val intKeys = smallKeys ++ Array(-1, Int.MaxValue, Int.MinValue, -129385) + val longKeys = intKeys.map(_.toLong) ++ Array(Long.MaxValue, Long.MinValue, 1397198789151L, -41402148014L) + val stringKeys = intKeys.map(_.toString) ++ Array("", null) + val anyKeys = stringKeys.filter(_ != null) ++ Array(0L) ++ Array(true) ++ Array(math.Pi) + + @Test + def churnIntMaps() { + val maps = Array[() => MapBox[Int]]( + () => boxMlm[Int], () => boxMhm[Int], () => boxMohm[Int], () => boxJavaM[Int], + () => boxIim, () => boxIhm[Int], () => boxIlm[Int], () => boxItm[Int] + ) + assert( maps.sliding(2).forall{ ms => churn(ms(0)(), ms(1)(), intKeys, 2000) } ) + } + + @Test + def churnLongMaps() { + val maps = Array[() => MapBox[Long]]( + () => boxMjm, () => boxIjm, () => boxJavaM[Long], + () => boxMlm[Long], () => boxMhm[Long], () => boxMohm[Long], () => boxIhm[Long], () => boxIlm[Long] + ) + assert( maps.sliding(2).forall{ ms => churn(ms(0)(), ms(1)(), longKeys, 10000) } ) + } + + @Test + def churnStringMaps() { + // Note: OpenHashMap and TreeMap won't store null, so skip strings + val maps = Array[() => MapBox[String]]( + () => boxMlm[String], () => boxMhm[String], () => boxMarm[String], () => boxJavaM[String], + () => boxIhm[String], () => boxIlm[String] + ) + assert( maps.sliding(2).forall{ ms => churn(ms(0)(), ms(1)(), stringKeys, 5000) } ) + } + + @Test + def churnAnyMaps() { + val maps = Array[() => MapBox[Any]]( + () => boxMlm[Any], () => boxMhm[Any], () => boxMohm[Any], () => boxJavaM[Any], () => boxIhm[Any], () => boxIlm[Any] + ) + assert( maps.sliding(2).forall{ ms => churn(ms(0)(), ms(1)(), anyKeys, 10000) } ) + } + + @Test + def churnIntSets() { + val sets = Array[() => MapBox[Int]]( + () => boxMhm[Int], () => boxIhm[Int], () => boxJavaS[Int], + () => boxMbs, () => boxMhs[Int], () => boxIbs, () => boxIhs[Int], () => boxIls[Int], () => boxIts[Int] + ) + assert( sets.sliding(2).forall{ ms => churn(ms(0)(), ms(1)(), smallKeys, 1000, valuer = _ => 0) } ) + } + + @Test + def churnAnySets() { + val sets = Array[() => MapBox[Any]]( + () => boxMhm[Any], () => boxIhm[Any], () => boxJavaS[Any], + () => boxMhs[Any], () => boxIhs[Any], () => boxIls[Any] + ) + assert( sets.sliding(2).forall{ ms => churn(ms(0)(), ms(1)(), anyKeys, 10000, valuer = _ => 0) } ) + } + + @Test + def extraMutableLongMapTests() { + import cm.{LongMap, HashMap} + var lm = LongMap.empty[Long] + longKeys.zipWithIndex.foreach{ case (k,i) => lm(k) = i } + assert{ lm.map{ case (k,v) => -k*k -> v.toString }.getClass == lm.getClass } + + assert { + val lm2 = new LongMap[Unit](2000000) + for (i <- 0 until 1000000) lm2(i) = () + + lm2.size == 1000000 && + (0 to 1100000 by 100000).forall(i => (lm2 contains i) == i < 1000000) + } + + lm = LongMap(8L -> 22L, -5L -> 5L, Long.MinValue -> 0L) + + assert{ var s = 0L; lm.foreachKey(s += _); s == Long.MinValue + 3 } + assert{ var s = 0L; lm.foreachValue(s += _); s == 27L } + assert { + val m2 = lm.mapValuesNow(_+2) + lm.transformValues(_+2) + m2 == lm && !(m2 eq lm) && (for ((_,v) <- lm) yield v).sum == 33L + } + + assert { + val lm2 = new LongMap[String](_.toString) + lm2 += (5L -> "fish", 0L -> "unicorn") + val hm2 = (new HashMap[Long,String]) ++= lm2 + List(Long.MinValue, 0L, 1L, 5L).forall(i => + lm2.get(i) == hm2.get(i) && + lm2.getOrElse(i, "") == hm2.getOrElse(i, "") && + lm2(i) == hm2.get(i).getOrElse(i.toString) && + lm2.getOrNull(i) == hm2.get(i).orNull + ) + } + } + + @Test + def extraMutableAnyRefMapTests() { + import cm.{AnyRefMap, HashMap} + var arm = AnyRefMap.empty[String, Int] + stringKeys.zipWithIndex.foreach{ case (k,i) => arm(k) = i } + + assert{ arm.map{ case (k,v) => (if (k==null) "" else k+k) -> v.toString }.getClass == arm.getClass } + + assert { + val arm2 = new AnyRefMap[java.lang.Integer,Unit](2000000) + for (i <- 0 until 1000000) arm2(java.lang.Integer.valueOf(i)) = () + arm2.size == 1000000 && + (0 to 1100000 by 100000).map(java.lang.Integer.valueOf).forall(i => (arm2 contains i) == i < 1000000) + } + + arm = AnyRefMap("heron" -> 22, "dove" -> 5, "budgie" -> 0) + + assert{ + var s = "" + arm.foreachKey(s += _) + s.length == "herondovebudgie".length && + s.contains("heron") && + s.contains("dove") && + s.contains("budgie") + } + + assert{ var s = 0L; arm.foreachValue(s += _); s == 27L } + + assert { + val m2 = arm.mapValuesNow(_+2) + arm.transformValues(_+2) + m2 == arm && !(m2 eq arm) && (for ((_,v) <- arm) yield v).sum == 33L + } + + assert { + val arm2 = new AnyRefMap[String, String](x => if (x==null) "null" else x) + arm2 += ("cod" -> "fish", "Rarity" -> "unicorn") + val hm2 = (new HashMap[String,String]) ++= arm2 + List(null, "cod", "sparrow", "Rarity").forall(i => + arm2.get(i) == hm2.get(i) && + arm2.getOrElse(i, "") == hm2.getOrElse(i, "") && + arm2(i) == hm2.get(i).getOrElse(if (i==null) "null" else i.toString) && + arm2.getOrNull(i) == hm2.get(i).orNull + ) + } + } + + @Test + def extraFilterTests() { + type M = scala.collection.Map[Int, Boolean] + val manyKVs = (0 to 1000).map(i => i*i*i).map(x => x -> ((x*x*x) < 0)) + val rn = new scala.util.Random(42) + def mhm: M = { val m = new cm.HashMap[Int, Boolean]; m ++= manyKVs; m } + def mohm: M = { val m = new cm.OpenHashMap[Int, Boolean]; m ++= manyKVs; m } + def ihm: M = ci.HashMap.empty[Int, Boolean] ++ manyKVs + val densities = List(0, 0.05, 0.2, 0.5, 0.8, 0.95, 1) + def repeat = rn.nextInt(100) < 33 + def pick(m: M, density: Double) = m.keys.filter(_ => rn.nextDouble < density).toSet + def test: Boolean = { + for (i <- 0 to 100) { + var ms = List(mhm, mohm, ihm) + do { + val density = densities(rn.nextInt(densities.length)) + val keep = pick(ms.head, density) + ms = ms.map(_.filter(keep contains _._1)) + if (!ms.sliding(2).forall(s => s(0) == s(1))) return false + } while (repeat) + } + true + } + assert(test) + } +} diff --git a/test/junit/scala/math/NumericTest.scala b/test/junit/scala/math/NumericTest.scala new file mode 100644 index 0000000000..4f0657f471 --- /dev/null +++ b/test/junit/scala/math/NumericTest.scala @@ -0,0 +1,18 @@ + + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(classOf[JUnit4]) +class NumericTest { + + /* Test for SI-8102 */ + @Test + def testAbs { + assertTrue(-0.0.abs equals 0.0) + assertTrue(-0.0f.abs equals 0.0f) + } +} + diff --git a/test/junit/scala/reflect/internal/MirrorsTest.scala b/test/junit/scala/reflect/internal/MirrorsTest.scala new file mode 100644 index 0000000000..9108af139f --- /dev/null +++ b/test/junit/scala/reflect/internal/MirrorsTest.scala @@ -0,0 +1,18 @@ +package scala.reflect.internal + +import org.junit.Assert._ +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(classOf[JUnit4]) +class MirrorsTest { + @Test def rootCompanionsAreConnected(): Unit = { + val cm = scala.reflect.runtime.currentMirror + import cm._ + assertEquals("RootPackage.moduleClass == RootClass", RootClass, RootPackage.moduleClass) + assertEquals("RootClass.module == RootPackage", RootPackage, RootClass.module) + assertEquals("EmptyPackage.moduleClass == EmptyPackageClass", EmptyPackageClass, EmptyPackage.moduleClass) + assertEquals("EmptyPackageClass.module == EmptyPackage", EmptyPackage, EmptyPackageClass.module) + } +}
\ No newline at end of file diff --git a/test/pending/run/idempotency-partial-functions.scala b/test/pending/run/idempotency-partial-functions.scala index bc0ca706dd..e673da5a29 100644 --- a/test/pending/run/idempotency-partial-functions.scala +++ b/test/pending/run/idempotency-partial-functions.scala @@ -20,7 +20,7 @@ object Test extends App { case e: ToolBoxError => println(e) } val tb = cm.mkToolBox() - val tpartials = tb.typeCheck(partials.tree) + val tpartials = tb.typecheck(partials.tree) println(tpartials) val rtpartials = tb.resetAllAttrs(tpartials) println(tb.eval(rtpartials)) diff --git a/test/pending/run/t5943b1.scala b/test/pending/run/t5943b1.scala index 0d54718753..79c638fedc 100644 --- a/test/pending/run/t5943b1.scala +++ b/test/pending/run/t5943b1.scala @@ -6,5 +6,5 @@ import scala.tools.reflect.ToolBox object Test extends App { val tb = cm.mkToolBox() val expr = tb.parse("math.sqrt(4.0)") - println(tb.typeCheck(expr)) + println(tb.typecheck(expr)) }
\ No newline at end of file |