scala> val input = readLine("hello %s%n", "world")
hello WrappedArray(world)
input: String = ""
scala> val input = Console.readLine("hello %s%n", "world")
hello world
input: String = ""
What’s the reason for the difference here? (I tried it compiled as well, so it’s not a REPL thing.)
Scala version 2.9.0-1
It seems like a bug in
Predef:When I think it should be:
The first version you use is calling
Prefef.readLine. Because of the missing_*type ascription, the function is called withargsas the single first argument of the repeated argumentargsofConsole.readLine.In the uncurry compilation phase, this single argument is wrapped into a
WrappedArrayso that it it can be treated as aSeq[Any]. TheWrappedArrayis then converted using thetoStringmethod and this is what is used for%sin"hello %s%n". I think that is what happens.In the second version
argsis treated from the start as aSeq[Any]and no conversion happens.The whole thing is a bit funny, because in general the compiler does not let you do this:
With
Any, you get past the typer phase.