summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/files/neg/forgot-interpolator.check21
-rw-r--r--test/files/neg/forgot-interpolator.scala32
-rw-r--r--test/files/neg/macro-quasiquotes.check2
-rw-r--r--test/files/neg/t7848-interp-warn.check9
-rw-r--r--test/files/neg/t7848-interp-warn.flags1
-rw-r--r--test/files/neg/t7848-interp-warn.scala13
-rw-r--r--test/files/pos/t7864.flags1
-rw-r--r--test/files/pos/t7864.scala5
-rw-r--r--test/files/run/t6719.check1
-rw-r--r--test/files/run/t6719.scala8
-rw-r--r--test/files/run/t7852.check0
-rw-r--r--test/files/run/t7852.flags1
-rw-r--r--test/files/run/t7852.scala39
-rw-r--r--test/files/scalacheck/quasiquotes/TermConstructionProps.scala24
-rw-r--r--test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala20
15 files changed, 173 insertions, 4 deletions
diff --git a/test/files/neg/forgot-interpolator.check b/test/files/neg/forgot-interpolator.check
index f6de4d7b3a..a96431841f 100644
--- a/test/files/neg/forgot-interpolator.check
+++ b/test/files/neg/forgot-interpolator.check
@@ -1,9 +1,24 @@
-forgot-interpolator.scala:4: warning: looks like an interpolated String; did you forget the interpolator?
+forgot-interpolator.scala:4: warning: `$bippy` looks like an interpolated identifier! Did you forget the interpolator?
def f = "Put the $bippy in the $bippy!" // warn
^
-forgot-interpolator.scala:14: warning: looks like an interpolated String; did you forget the interpolator?
+forgot-interpolator.scala:14: warning: That looks like an interpolated expression! Did you forget the interpolator?
def f = """Put the ${println("bippy")} in the bippy!""" // warn
^
+forgot-interpolator.scala:30: warning: `$beppo` looks like an interpolated identifier! Did you forget the interpolator?
+ def f = "$beppo was a marx bros who saw dollars." // warn
+ ^
+forgot-interpolator.scala:34: warning: `$aleppo` looks like an interpolated identifier! Did you forget the interpolator?
+ def f = "$aleppo is a pepper and a city." // warn
+ ^
+forgot-interpolator.scala:40: warning: `$bar` looks like an interpolated identifier! Did you forget the interpolator?
+ def f = "$bar is private, shall we warn just in case?" // warn
+ ^
+forgot-interpolator.scala:45: warning: `$hippo` looks like an interpolated identifier! Did you forget the interpolator?
+ def h = "$hippo takes an implicit" // warn
+ ^
+forgot-interpolator.scala:37: warning: private method in class Bar is never used
+ private def bar = 8
+ ^
error: No warnings can be incurred under -Xfatal-warnings.
-two warnings found
+7 warnings found
one error found
diff --git a/test/files/neg/forgot-interpolator.scala b/test/files/neg/forgot-interpolator.scala
index d67db82643..5067f1dce9 100644
--- a/test/files/neg/forgot-interpolator.scala
+++ b/test/files/neg/forgot-interpolator.scala
@@ -13,3 +13,35 @@ class B {
class C {
def f = """Put the ${println("bippy")} in the bippy!""" // warn
}
+
+package object test {
+ def aleppo = 9
+ def greppo(n: Int) = ???
+ def zappos(n: Int)(implicit ord: math.Ordering[Int]) = ???
+ def hippo(implicit n: Int) = ???
+}
+
+package test {
+ // not sure if overloading is kosher in pkg obj yet
+ class Doo {
+ def beppo(i: Int) = 8 * i
+ def beppo = 8
+ class Dah extends Doo {
+ def f = "$beppo was a marx bros who saw dollars." // warn
+ }
+ }
+ class E {
+ def f = "$aleppo is a pepper and a city." // warn
+ }
+ class Bar {
+ private def bar = 8
+ }
+ class Baz extends Bar {
+ def f = "$bar is private, shall we warn just in case?" // warn
+ }
+ class G {
+ def g = "$greppo takes an arg" // no warn
+ def z = "$zappos takes an arg too" // no warn
+ def h = "$hippo takes an implicit" // warn
+ }
+}
diff --git a/test/files/neg/macro-quasiquotes.check b/test/files/neg/macro-quasiquotes.check
index a2d48723b5..96ef75dd32 100644
--- a/test/files/neg/macro-quasiquotes.check
+++ b/test/files/neg/macro-quasiquotes.check
@@ -1,6 +1,6 @@
Macros_1.scala:14: error: macro implementation has wrong shape:
required: (x: Impls.this.c.Expr[Int]): Impls.this.c.Expr[Any]
- found : (x: Impls.this.c.universe.Block): Impls.this.c.universe.Apply
+ found : (x: Impls.this.c.universe.Block): Impls.this.c.universe.Tree
type mismatch for parameter x: Impls.this.c.Expr[Int] does not conform to Impls.this.c.universe.Block
def m3(x: Int) = macro Impls.impl3
^
diff --git a/test/files/neg/t7848-interp-warn.check b/test/files/neg/t7848-interp-warn.check
new file mode 100644
index 0000000000..cbdc9f4c27
--- /dev/null
+++ b/test/files/neg/t7848-interp-warn.check
@@ -0,0 +1,9 @@
+t7848-interp-warn.scala:7: warning: `$foo` looks like an interpolated identifier! Did you forget the interpolator?
+ "An important $foo message!"
+ ^
+t7848-interp-warn.scala:11: warning: That looks like an interpolated expression! Did you forget the interpolator?
+ "A doubly important ${foo * 2} message!"
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/files/neg/t7848-interp-warn.flags b/test/files/neg/t7848-interp-warn.flags
new file mode 100644
index 0000000000..7949c2afa2
--- /dev/null
+++ b/test/files/neg/t7848-interp-warn.flags
@@ -0,0 +1 @@
+-Xlint -Xfatal-warnings
diff --git a/test/files/neg/t7848-interp-warn.scala b/test/files/neg/t7848-interp-warn.scala
new file mode 100644
index 0000000000..bb3eeff60c
--- /dev/null
+++ b/test/files/neg/t7848-interp-warn.scala
@@ -0,0 +1,13 @@
+
+package test
+
+object Test {
+ def f = {
+ val foo = "bar"
+ "An important $foo message!"
+ }
+ def g = {
+ val foo = "bar"
+ "A doubly important ${foo * 2} message!"
+ }
+}
diff --git a/test/files/pos/t7864.flags b/test/files/pos/t7864.flags
new file mode 100644
index 0000000000..7ccd56103a
--- /dev/null
+++ b/test/files/pos/t7864.flags
@@ -0,0 +1 @@
+-Xlint \ No newline at end of file
diff --git a/test/files/pos/t7864.scala b/test/files/pos/t7864.scala
new file mode 100644
index 0000000000..b2d8911a17
--- /dev/null
+++ b/test/files/pos/t7864.scala
@@ -0,0 +1,5 @@
+object Test {
+ val f = 0;
+ ({ toString; (x: Any) => x})("$f ")
+}
+
diff --git a/test/files/run/t6719.check b/test/files/run/t6719.check
new file mode 100644
index 0000000000..6a452c185a
--- /dev/null
+++ b/test/files/run/t6719.check
@@ -0,0 +1 @@
+()
diff --git a/test/files/run/t6719.scala b/test/files/run/t6719.scala
new file mode 100644
index 0000000000..847929a95d
--- /dev/null
+++ b/test/files/run/t6719.scala
@@ -0,0 +1,8 @@
+import scala.reflect.runtime.universe._
+import scala.reflect.runtime.{currentMirror => cm}
+import scala.tools.reflect.{ToolBox, ToolBoxError}
+object Test extends App {
+ val tb = cm.mkToolBox()
+ val tree = tb.parse("(); val res = 0")
+ println(tb.eval(tree))
+} \ No newline at end of file
diff --git a/test/files/run/t7852.check b/test/files/run/t7852.check
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/files/run/t7852.check
diff --git a/test/files/run/t7852.flags b/test/files/run/t7852.flags
new file mode 100644
index 0000000000..f6262fd3e0
--- /dev/null
+++ b/test/files/run/t7852.flags
@@ -0,0 +1 @@
+-Ynooptimise
diff --git a/test/files/run/t7852.scala b/test/files/run/t7852.scala
new file mode 100644
index 0000000000..c93db718fd
--- /dev/null
+++ b/test/files/run/t7852.scala
@@ -0,0 +1,39 @@
+import scala.tools.partest.BytecodeTest
+import scala.tools.asm
+import scala.tools.asm.util._
+import scala.tools.nsc.util.stringFromWriter
+import scala.collection.JavaConverters._
+
+object Test extends BytecodeTest {
+ val nullChecks = Set(asm.Opcodes.IFNONNULL, asm.Opcodes.IFNULL)
+
+ def show: Unit = {
+ def test(methodName: String, expected: Int) {
+ val classNode = loadClassNode("Lean")
+ val methodNode = getMethod(classNode, methodName)
+ val got = countNullChecks(methodNode.instructions)
+ assert(got == expected, s"expected $expected but got $got comparisons")
+ }
+ test("string", expected = 0)
+ test("module", expected = 0)
+ test("moduleIndirect", expected = 2)
+ }
+
+ def countNullChecks(insnList: asm.tree.InsnList): Int =
+ insnList.iterator.asScala.map(_.getOpcode).count(nullChecks)
+}
+
+class Lean {
+ def string {
+ "" == toString
+ }
+
+ def module {
+ Nil == (toString: Any)
+ }
+
+ def moduleIndirect {
+ val n: Nil.type = null
+ n == (toString: Any) // still need null checks here.
+ }
+}
diff --git a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala
index c6cca85c81..753ad1aa59 100644
--- a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala
+++ b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala
@@ -167,4 +167,28 @@ object TermConstructionProps extends QuasiquoteProperties("term construction") {
val x = q"val x: Int = 1"
assertThrows[IllegalArgumentException] { q"($x) => x" }
}
+
+ property("assign variable") = test {
+ val v = q"v"
+ val value = q"foo"
+ assertEqAst(q"$v = $value", "v = foo")
+ }
+
+ property("assign update 1") = test {
+ val v = q"v"
+ val args = q"1" :: q"2" :: Nil
+ val value = q"foo"
+ assertEqAst(q"$v(..$args) = $value", "v(1, 2) = foo")
+ }
+
+ property("assign update 2") = test {
+ val a = q"v(0)"
+ val value = q"foo"
+ assertEqAst(q"$a = $value", "v(0) = foo")
+ }
+
+ property("assign or named arg") = test {
+ val assignx = q"x = 1"
+ assertEqAst(q"f($assignx)", "f(x = 1)")
+ }
}
diff --git a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala b/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala
index 45c7ee4bb7..22d4b1ce4f 100644
--- a/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala
+++ b/test/files/scalacheck/quasiquotes/TermDeconstructionProps.scala
@@ -91,4 +91,24 @@ object TermDeconstructionProps extends QuasiquoteProperties("term deconstruction
matches("new { val early = 1} with Parent[Int] { body }")
matches("new Foo { selfie => }")
}
+
+ property("exhaustive assign pattern") = test {
+ def matches(tree: Tree) { val q"$rhs = $lhs" = tree }
+ matches(parse("left = right"))
+ matches(parse("arr(1) = 2"))
+ matches(AssignOrNamedArg(EmptyTree, EmptyTree))
+ }
+
+ property("deconstruct update 1") = test {
+ val q"$obj(..$args) = $value" = q"foo(bar) = baz"
+ assert(obj ≈ q"foo")
+ assert(args ≈ List(q"bar"))
+ assert(value ≈ q"baz")
+ }
+
+ property("deconstruct update 2") = test {
+ val q"$left = $value" = q"foo(bar) = baz"
+ assert(left ≈ q"foo(bar)")
+ assert(value ≈ q"baz")
+ }
}