From b97d44b2d813c1bf482b23efb353e4550818700c Mon Sep 17 00:00:00 2001 From: Den Shabalin Date: Sun, 8 Dec 2013 20:18:56 +0100 Subject: SI-8047 change fresh name encoding to avoid owner corruption MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously a following encoding was used to represent fresh names that should be created at runtime of the quasiquote: build.withFreshTermName(prefix1) { name$1 => ... build.withFreshTermName(prefixN) { name$N => tree } ... } It turned out that this encoding causes symbol corruption when tree defines symbols of its own. After being spliced into anonymous functions, the owner chain of those symbols will become corrupted. Now a simpler and probably better performing alternative is used instead: { val name$1 = universe.build.freshTermName(prefix1) ... val name$N = universe.build.freshTermName(prefixN) tree } Here owner stays the same and doesn’t need any adjustment. --- test/files/run/t8047.check | 7 +++++++ test/files/run/t8047.scala | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/files/run/t8047.check create mode 100644 test/files/run/t8047.scala (limited to 'test/files') 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)") +} -- cgit v1.2.3 From 71a2102a2df3721e0b8d0a9a5e87d01eb849dadd Mon Sep 17 00:00:00 2001 From: Den Shabalin Date: Mon, 16 Dec 2013 13:59:34 +0100 Subject: Use t- prefix instead of si- prefix for test files --- test/files/jvm/si5471.check | 2 - test/files/jvm/si5471.scala | 17 ------- test/files/jvm/t5471.check | 2 + test/files/jvm/t5471.scala | 17 +++++++ test/files/run/reify_renamed_term_si5841.check | 1 - test/files/run/reify_renamed_term_si5841.scala | 7 --- test/files/run/reify_renamed_term_t5841.check | 1 + test/files/run/reify_renamed_term_t5841.scala | 7 +++ test/files/run/si4750.check | 1 - test/files/run/si4750.scala | 7 --- test/files/run/si5045.check | 6 --- test/files/run/si5045.scala | 49 ------------------- test/files/run/t4750.check | 1 + test/files/run/t4750.scala | 7 +++ test/files/run/t5045.check | 6 +++ test/files/run/t5045.scala | 49 +++++++++++++++++++ test/files/scalacheck/si4147.scala | 68 -------------------------- test/files/scalacheck/t4147.scala | 68 ++++++++++++++++++++++++++ 18 files changed, 158 insertions(+), 158 deletions(-) delete mode 100644 test/files/jvm/si5471.check delete mode 100644 test/files/jvm/si5471.scala create mode 100644 test/files/jvm/t5471.check create mode 100644 test/files/jvm/t5471.scala delete mode 100644 test/files/run/reify_renamed_term_si5841.check delete mode 100644 test/files/run/reify_renamed_term_si5841.scala create mode 100644 test/files/run/reify_renamed_term_t5841.check create mode 100644 test/files/run/reify_renamed_term_t5841.scala delete mode 100644 test/files/run/si4750.check delete mode 100644 test/files/run/si4750.scala delete mode 100644 test/files/run/si5045.check delete mode 100644 test/files/run/si5045.scala create mode 100644 test/files/run/t4750.check create mode 100644 test/files/run/t4750.scala create mode 100644 test/files/run/t5045.check create mode 100644 test/files/run/t5045.scala delete mode 100644 test/files/scalacheck/si4147.scala create mode 100644 test/files/scalacheck/t4147.scala (limited to 'test/files') diff --git a/test/files/jvm/si5471.check b/test/files/jvm/si5471.check deleted file mode 100644 index bb101b641b..0000000000 --- a/test/files/jvm/si5471.check +++ /dev/null @@ -1,2 +0,0 @@ -true -true diff --git a/test/files/jvm/si5471.scala b/test/files/jvm/si5471.scala deleted file mode 100644 index 2efd869b61..0000000000 --- a/test/files/jvm/si5471.scala +++ /dev/null @@ -1,17 +0,0 @@ - -object Test { - - def main(args: Array[String]) { - import scala.math.Numeric - import scala.math.Numeric.Implicits._ - - val b = BigInt(Long.MaxValue) + 1 - - def dbl[N :Numeric](n: N) = n.toDouble - def flt[N :Numeric](n: N) = n.toFloat - - println(dbl(b) == b.toDouble) - println(flt(b) == b.toFloat) - } - -} diff --git a/test/files/jvm/t5471.check b/test/files/jvm/t5471.check new file mode 100644 index 0000000000..bb101b641b --- /dev/null +++ b/test/files/jvm/t5471.check @@ -0,0 +1,2 @@ +true +true diff --git a/test/files/jvm/t5471.scala b/test/files/jvm/t5471.scala new file mode 100644 index 0000000000..2efd869b61 --- /dev/null +++ b/test/files/jvm/t5471.scala @@ -0,0 +1,17 @@ + +object Test { + + def main(args: Array[String]) { + import scala.math.Numeric + import scala.math.Numeric.Implicits._ + + val b = BigInt(Long.MaxValue) + 1 + + def dbl[N :Numeric](n: N) = n.toDouble + def flt[N :Numeric](n: N) = n.toFloat + + println(dbl(b) == b.toDouble) + println(flt(b) == b.toFloat) + } + +} diff --git a/test/files/run/reify_renamed_term_si5841.check b/test/files/run/reify_renamed_term_si5841.check deleted file mode 100644 index 6031277b76..0000000000 --- a/test/files/run/reify_renamed_term_si5841.check +++ /dev/null @@ -1 +0,0 @@ -class scala.reflect.runtime.JavaUniverse diff --git a/test/files/run/reify_renamed_term_si5841.scala b/test/files/run/reify_renamed_term_si5841.scala deleted file mode 100644 index ef18d650bf..0000000000 --- a/test/files/run/reify_renamed_term_si5841.scala +++ /dev/null @@ -1,7 +0,0 @@ -import scala.reflect.runtime.universe._ -import scala.reflect.runtime.{universe => ru} -import scala.tools.reflect.Eval - -object Test extends App { - println(reify{ru}.eval.getClass) -} \ No newline at end of file diff --git a/test/files/run/reify_renamed_term_t5841.check b/test/files/run/reify_renamed_term_t5841.check new file mode 100644 index 0000000000..6031277b76 --- /dev/null +++ b/test/files/run/reify_renamed_term_t5841.check @@ -0,0 +1 @@ +class scala.reflect.runtime.JavaUniverse diff --git a/test/files/run/reify_renamed_term_t5841.scala b/test/files/run/reify_renamed_term_t5841.scala new file mode 100644 index 0000000000..ef18d650bf --- /dev/null +++ b/test/files/run/reify_renamed_term_t5841.scala @@ -0,0 +1,7 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.tools.reflect.Eval + +object Test extends App { + println(reify{ru}.eval.getClass) +} \ No newline at end of file diff --git a/test/files/run/si4750.check b/test/files/run/si4750.check deleted file mode 100644 index bf55f70df3..0000000000 --- a/test/files/run/si4750.check +++ /dev/null @@ -1 +0,0 @@ -US$ 5.80 diff --git a/test/files/run/si4750.scala b/test/files/run/si4750.scala deleted file mode 100644 index 96d2c4fec7..0000000000 --- a/test/files/run/si4750.scala +++ /dev/null @@ -1,7 +0,0 @@ -import scala.util.matching.Regex - -object Test extends App { - val input = "CURRENCY 5.80" - println("CURRENCY".r.replaceAllIn(input, Regex quoteReplacement "US$")) -} - diff --git a/test/files/run/si5045.check b/test/files/run/si5045.check deleted file mode 100644 index 7e9c1961b7..0000000000 --- a/test/files/run/si5045.check +++ /dev/null @@ -1,6 +0,0 @@ - extract an exact match 2011-07-15 2011-07-15 - extract from middle of string 2011-07-15 2011-07-15 - extract from middle of string (P2) 2011-07-15 2011-07-15 - extract from middle of string (P3) 2011-07-15 2011-07-15 - copyright example has date Copyright 2011 Copyright 2011 - copyright example missing date No copyright No copyright diff --git a/test/files/run/si5045.scala b/test/files/run/si5045.scala deleted file mode 100644 index b0c3a4ddc4..0000000000 --- a/test/files/run/si5045.scala +++ /dev/null @@ -1,49 +0,0 @@ - -import scala.language.postfixOps - -object Test extends App { - - import scala.util.matching.{ Regex, UnanchoredRegex } - - val dateP1 = """(\d\d\d\d)-(\d\d)-(\d\d)""".r.unanchored - val dateP2 = """(\d\d\d\d)-(\d\d)-(\d\d)""" r ("year", "month", "day") unanchored - val dateP3 = new Regex("""(\d\d\d\d)-(\d\d)-(\d\d)""", "year", "month", "day") with UnanchoredRegex - - val yearStr = "2011" - val dateStr = List(yearStr,"07","15").mkString("-") - - def test(msg: String)(strs: Seq[String]): Unit = println("%40s %s".format(msg, strs mkString " ")) - - test("extract an exact match") { - val dateP1(y,m,d) = dateStr - Seq(List(y,m,d).mkString("-"), dateStr) - } - - test("extract from middle of string") { - val dateP1(y,m,d) = "Tested on "+dateStr+"." - Seq(List(y,m,d).mkString("-"), dateStr) - } - - test("extract from middle of string (P2)") { - val dateP2(y,m,d) = "Tested on "+dateStr+"." - Seq(List(y,m,d).mkString("-"), dateStr) - } - - test("extract from middle of string (P3)") { - val dateP2(y,m,d) = "Tested on "+dateStr+"." - Seq(List(y,m,d).mkString("-"), dateStr) - } - - def copyright(in: String): String = in match { - case dateP1(year, month, day) => "Copyright "+year - case _ => "No copyright" - } - - test("copyright example has date") { - Seq(copyright("Date of this document: "+dateStr), "Copyright "+yearStr) - } - - test("copyright example missing date") { - Seq(copyright("Date of this document: unknown"), "No copyright") - } -} diff --git a/test/files/run/t4750.check b/test/files/run/t4750.check new file mode 100644 index 0000000000..bf55f70df3 --- /dev/null +++ b/test/files/run/t4750.check @@ -0,0 +1 @@ +US$ 5.80 diff --git a/test/files/run/t4750.scala b/test/files/run/t4750.scala new file mode 100644 index 0000000000..96d2c4fec7 --- /dev/null +++ b/test/files/run/t4750.scala @@ -0,0 +1,7 @@ +import scala.util.matching.Regex + +object Test extends App { + val input = "CURRENCY 5.80" + println("CURRENCY".r.replaceAllIn(input, Regex quoteReplacement "US$")) +} + diff --git a/test/files/run/t5045.check b/test/files/run/t5045.check new file mode 100644 index 0000000000..7e9c1961b7 --- /dev/null +++ b/test/files/run/t5045.check @@ -0,0 +1,6 @@ + extract an exact match 2011-07-15 2011-07-15 + extract from middle of string 2011-07-15 2011-07-15 + extract from middle of string (P2) 2011-07-15 2011-07-15 + extract from middle of string (P3) 2011-07-15 2011-07-15 + copyright example has date Copyright 2011 Copyright 2011 + copyright example missing date No copyright No copyright diff --git a/test/files/run/t5045.scala b/test/files/run/t5045.scala new file mode 100644 index 0000000000..b0c3a4ddc4 --- /dev/null +++ b/test/files/run/t5045.scala @@ -0,0 +1,49 @@ + +import scala.language.postfixOps + +object Test extends App { + + import scala.util.matching.{ Regex, UnanchoredRegex } + + val dateP1 = """(\d\d\d\d)-(\d\d)-(\d\d)""".r.unanchored + val dateP2 = """(\d\d\d\d)-(\d\d)-(\d\d)""" r ("year", "month", "day") unanchored + val dateP3 = new Regex("""(\d\d\d\d)-(\d\d)-(\d\d)""", "year", "month", "day") with UnanchoredRegex + + val yearStr = "2011" + val dateStr = List(yearStr,"07","15").mkString("-") + + def test(msg: String)(strs: Seq[String]): Unit = println("%40s %s".format(msg, strs mkString " ")) + + test("extract an exact match") { + val dateP1(y,m,d) = dateStr + Seq(List(y,m,d).mkString("-"), dateStr) + } + + test("extract from middle of string") { + val dateP1(y,m,d) = "Tested on "+dateStr+"." + Seq(List(y,m,d).mkString("-"), dateStr) + } + + test("extract from middle of string (P2)") { + val dateP2(y,m,d) = "Tested on "+dateStr+"." + Seq(List(y,m,d).mkString("-"), dateStr) + } + + test("extract from middle of string (P3)") { + val dateP2(y,m,d) = "Tested on "+dateStr+"." + Seq(List(y,m,d).mkString("-"), dateStr) + } + + def copyright(in: String): String = in match { + case dateP1(year, month, day) => "Copyright "+year + case _ => "No copyright" + } + + test("copyright example has date") { + Seq(copyright("Date of this document: "+dateStr), "Copyright "+yearStr) + } + + test("copyright example missing date") { + Seq(copyright("Date of this document: unknown"), "No copyright") + } +} diff --git a/test/files/scalacheck/si4147.scala b/test/files/scalacheck/si4147.scala deleted file mode 100644 index 72f6e9afd5..0000000000 --- a/test/files/scalacheck/si4147.scala +++ /dev/null @@ -1,68 +0,0 @@ -import org.scalacheck.Prop.{forAll, throws} -import org.scalacheck.Properties -import org.scalacheck.Gen - - -import collection.mutable - - -object Test extends Properties("Mutable TreeSet") { - - val generator = Gen.listOfN(1000, Gen.chooseNum(0, 1000)) - - val denseGenerator = Gen.listOfN(1000, Gen.chooseNum(0, 200)) - - property("Insertion doesn't allow duplicates values.") = forAll(generator) { (s: List[Int]) => - { - val t = mutable.TreeSet[Int](s: _*) - t == s.toSet - } - } - - property("Verification of size method validity") = forAll(generator) { (s: List[Int]) => - { - val t = mutable.TreeSet[Int](s: _*) - for (a <- s) { - t -= a - } - t.size == 0 - } - } - - property("All inserted elements are removed") = forAll(generator) { (s: List[Int]) => - { - val t = mutable.TreeSet[Int](s: _*) - for (a <- s) { - t -= a - } - t == Set() - } - } - - property("Elements are sorted.") = forAll(generator) { (s: List[Int]) => - { - val t = mutable.TreeSet[Int](s: _*) - t.toList == s.distinct.sorted - } - } - - property("Implicit CanBuildFrom resolution succeeds as well as the \"same-result-type\" principle.") = - forAll(generator) { (s: List[Int]) => - { - val t = mutable.TreeSet[Int](s: _*) - val t2 = t.map(_ * 2) - t2.isInstanceOf[collection.mutable.TreeSet[Int]] - } - } - - property("A view doesn't expose off bounds elements") = forAll(denseGenerator) { (s: List[Int]) => - { - val t = mutable.TreeSet[Int](s: _*) - val view = t.rangeImpl(Some(50), Some(150)) - view.filter(_ < 50) == Set[Int]() && view.filter(_ >= 150) == Set[Int]() - } - } - - property("ordering must not be null") = - throws(classOf[NullPointerException])(mutable.TreeSet.empty[Int](null)) -} diff --git a/test/files/scalacheck/t4147.scala b/test/files/scalacheck/t4147.scala new file mode 100644 index 0000000000..72f6e9afd5 --- /dev/null +++ b/test/files/scalacheck/t4147.scala @@ -0,0 +1,68 @@ +import org.scalacheck.Prop.{forAll, throws} +import org.scalacheck.Properties +import org.scalacheck.Gen + + +import collection.mutable + + +object Test extends Properties("Mutable TreeSet") { + + val generator = Gen.listOfN(1000, Gen.chooseNum(0, 1000)) + + val denseGenerator = Gen.listOfN(1000, Gen.chooseNum(0, 200)) + + property("Insertion doesn't allow duplicates values.") = forAll(generator) { (s: List[Int]) => + { + val t = mutable.TreeSet[Int](s: _*) + t == s.toSet + } + } + + property("Verification of size method validity") = forAll(generator) { (s: List[Int]) => + { + val t = mutable.TreeSet[Int](s: _*) + for (a <- s) { + t -= a + } + t.size == 0 + } + } + + property("All inserted elements are removed") = forAll(generator) { (s: List[Int]) => + { + val t = mutable.TreeSet[Int](s: _*) + for (a <- s) { + t -= a + } + t == Set() + } + } + + property("Elements are sorted.") = forAll(generator) { (s: List[Int]) => + { + val t = mutable.TreeSet[Int](s: _*) + t.toList == s.distinct.sorted + } + } + + property("Implicit CanBuildFrom resolution succeeds as well as the \"same-result-type\" principle.") = + forAll(generator) { (s: List[Int]) => + { + val t = mutable.TreeSet[Int](s: _*) + val t2 = t.map(_ * 2) + t2.isInstanceOf[collection.mutable.TreeSet[Int]] + } + } + + property("A view doesn't expose off bounds elements") = forAll(denseGenerator) { (s: List[Int]) => + { + val t = mutable.TreeSet[Int](s: _*) + val view = t.rangeImpl(Some(50), Some(150)) + view.filter(_ < 50) == Set[Int]() && view.filter(_ >= 150) == Set[Int]() + } + } + + property("ordering must not be null") = + throws(classOf[NullPointerException])(mutable.TreeSet.empty[Int](null)) +} -- cgit v1.2.3