summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel C. Sobral <dcsobral@gmail.com>2012-01-17 17:26:59 -0200
committerDaniel C. Sobral <dcsobral@gmail.com>2012-01-17 17:26:59 -0200
commit76caa37f22b70b126563df8a5eeab1b8bf693fc9 (patch)
tree2480da56cb8bebd0aa2843e1c9b87c41957bd226
parent9d55bf45cd13107ad8f3e5e75737f37e75b22f90 (diff)
downloadscala-76caa37f22b70b126563df8a5eeab1b8bf693fc9.tar.gz
scala-76caa37f22b70b126563df8a5eeab1b8bf693fc9.tar.bz2
scala-76caa37f22b70b126563df8a5eeab1b8bf693fc9.zip
Fix check for number of arguments
Fix the test for number of arguments by passing all arguments instead of passing the argument list as a single argument. Add positive and negative tests for it.
-rw-r--r--src/library/scala/StringContext.scala4
-rw-r--r--test/files/run/interpolation.check6
-rw-r--r--test/files/run/interpolation.scala2
-rw-r--r--test/files/run/interpolationArgs.check2
-rw-r--r--test/files/run/interpolationArgs.flags1
-rw-r--r--test/files/run/interpolationArgs.scala5
6 files changed, 18 insertions, 2 deletions
diff --git a/src/library/scala/StringContext.scala b/src/library/scala/StringContext.scala
index 1f0b4c766e..6116547aa2 100644
--- a/src/library/scala/StringContext.scala
+++ b/src/library/scala/StringContext.scala
@@ -43,7 +43,7 @@ case class StringContext(parts: String*) {
* that does not start a valid escape sequence.
*/
def s(args: Any*) = {
- checkLengths(args)
+ checkLengths(args: _*)
val pi = parts.iterator
val ai = args.iterator
val bldr = new java.lang.StringBuilder(treatEscapes(pi.next))
@@ -83,7 +83,7 @@ case class StringContext(parts: String*) {
* format specifier `%s` and adding a corresponding argument string `"%"`.
*/
def f(args: Any*) = {
- checkLengths(args)
+ checkLengths(args: _*)
val pi = parts.iterator
val ai = args.iterator
val bldr = new java.lang.StringBuilder
diff --git a/test/files/run/interpolation.check b/test/files/run/interpolation.check
index 4c34e4c8c8..09579a800a 100644
--- a/test/files/run/interpolation.check
+++ b/test/files/run/interpolation.check
@@ -2,14 +2,20 @@ Bob is 1 years old
Bob is 1 years old
Bob will be 2 years old
Bob will be 2 years old
+1+1 = 2
+1+1 = 2
Bob is 12 years old
Bob is 12 years old
Bob will be 13 years old
Bob will be 13 years old
+12+1 = 13
+12+1 = 13
Bob is 123 years old
Bob is 123 years old
Bob will be 124 years old
Bob will be 124 years old
+123+1 = 124
+123+1 = 124
Best price: 10.0
Best price: 10.00
10.0% discount included
diff --git a/test/files/run/interpolation.scala b/test/files/run/interpolation.scala
index 232a180bcd..a0a185eaab 100644
--- a/test/files/run/interpolation.scala
+++ b/test/files/run/interpolation.scala
@@ -5,6 +5,8 @@ object Test extends App {
println(f"Bob is $n%2d years old")
println(s"Bob will be ${n+1} years old")
println(f"Bob will be ${n+1}%2d years old")
+ println(s"$n+1 = ${n+1}")
+ println(f"$n%d+1 = ${n+1}%d")
}
def test2(f: Float) = {
diff --git a/test/files/run/interpolationArgs.check b/test/files/run/interpolationArgs.check
new file mode 100644
index 0000000000..155991e618
--- /dev/null
+++ b/test/files/run/interpolationArgs.check
@@ -0,0 +1,2 @@
+java.lang.IllegalArgumentException: wrong number of arguments for interpolated string
+java.lang.IllegalArgumentException: wrong number of arguments for interpolated string
diff --git a/test/files/run/interpolationArgs.flags b/test/files/run/interpolationArgs.flags
new file mode 100644
index 0000000000..e1b37447c9
--- /dev/null
+++ b/test/files/run/interpolationArgs.flags
@@ -0,0 +1 @@
+-Xexperimental \ No newline at end of file
diff --git a/test/files/run/interpolationArgs.scala b/test/files/run/interpolationArgs.scala
new file mode 100644
index 0000000000..eb13767907
--- /dev/null
+++ b/test/files/run/interpolationArgs.scala
@@ -0,0 +1,5 @@
+object Test extends App {
+ try { scala.StringContext("p1", "p2", "p3").s("e1") } catch { case ex => println(ex) }
+ try { scala.StringContext("p1").s("e1") } catch { case ex => println(ex) }
+}
+