Flipped varargs eta-expansion behavior.
(T*)U now eta-expands to Seq[T] => U, not T* => U. There is a transition command line switch to get the old behavior for any who may have relied upon it: -Yeta-expand-keeps-star Closes SI-4176, no review. git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@25809 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
15564b2b69
commit
0a2098a2ad
|
|
@ -3092,7 +3092,7 @@ A type's typeSymbol should never be inspected directly.
|
|||
// Or false for Seq[A] => Seq[A]
|
||||
// (It will rewrite A* everywhere but method parameters.)
|
||||
// This is the specified behavior.
|
||||
private final val etaExpandKeepsStar = true
|
||||
protected def etaExpandKeepsStar = false
|
||||
|
||||
object dropRepeatedParamType extends TypeMap {
|
||||
def apply(tp: Type): Type = tp match {
|
||||
|
|
|
|||
|
|
@ -300,6 +300,12 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
|
|||
def lubDebug = (sys.props contains "scalac.debug.lub")
|
||||
}
|
||||
|
||||
// The current division between scala.reflect.* and scala.tools.nsc.* is pretty
|
||||
// clunky. It is often difficult to have a setting influence something without having
|
||||
// to create it on that side. For this one my strategy is a constant def at the file
|
||||
// where I need it, and then an override in Global with the setting.
|
||||
override protected val etaExpandKeepsStar = settings.etaExpandKeepsStar.value
|
||||
|
||||
// True if -Xscript has been set, indicating a script run.
|
||||
def isScriptRun = opt.script.isDefined
|
||||
|
||||
|
|
|
|||
|
|
@ -168,6 +168,7 @@ trait ScalaSettings extends AbsScalaSettings
|
|||
val Ynotnull = BooleanSetting ("-Ynotnull", "Enable (experimental and incomplete) scala.NotNull.")
|
||||
val YdepMethTpes = BooleanSetting ("-Ydependent-method-types", "Allow dependent method types.")
|
||||
val YmethodInfer = BooleanSetting ("-Yinfer-argument-types", "Infer types for arguments of overriden methods.")
|
||||
val etaExpandKeepsStar = BooleanSetting("-Yeta-expand-keeps-star", "Eta-expand varargs methods to T* rather than Seq[T]. This is a temporary option to ease transition.")
|
||||
val noSelfCheck = BooleanSetting ("-Yno-self-type-checks", "Suppress check for self-type conformance among inherited members.")
|
||||
val YvirtClasses = false // too embryonic to even expose as a -Y //BooleanSetting ("-Yvirtual-classes", "Support virtual classes")
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
eta-expand-star.scala:6: error: too many arguments for method apply: (v1: Seq[T])Unit in trait Function1
|
||||
g(1, 2)
|
||||
^
|
||||
one error found
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
object Test {
|
||||
def f[T](xs: T*): Unit = ()
|
||||
def g[T] = f[T] _
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
g(1, 2)
|
||||
}
|
||||
}
|
||||
|
|
@ -36,13 +36,13 @@ def testVarargs(x: Int*) = x.reduceLeft((x: Int, y: Int) => x + y)
|
|||
test("varargs", 4, testVarargs(1, 2, 1))
|
||||
|
||||
val testVarargsR = testVarargs _
|
||||
test("varargs r", 4, testVarargsR(1, 2, 1))
|
||||
test("varargs r", 4, testVarargsR(Seq(1, 2, 1)))
|
||||
|
||||
def testAll(x: Int, y: => Int, z: Int*) = x + y + z.size
|
||||
test("all", 5, testAll(1, 2, 22, 23))
|
||||
|
||||
val testAllR = testAll _
|
||||
test("all r", 7, testAllR(2, 3, 34, 35))
|
||||
test("all r", 7, testAllR(2, 3, Seq(34, 35)))
|
||||
|
||||
val testAllS: (Int, =>Int, Int*) => Int = testAll _
|
||||
test("all s", 8, testAllS(1, 5, 78, 89))
|
||||
|
|
@ -73,7 +73,7 @@ def testCVV(a: Int*)(z: String, b: Int*) = a.size + b.size
|
|||
test("cvv", 3, testCVV(1, 2)("", 8))
|
||||
|
||||
val testCVVR = testCVV _
|
||||
test("cvv r", 3, testCVVR(1)("", 8, 9))
|
||||
test("cvv r", 3, testCVVR(Seq(1))("", Seq(8, 9)))
|
||||
|
||||
val testCVVRS: (String, Int*) => Int = testCVV(2, 3)
|
||||
test("cvv rs", 4, testCVVRS("", 5, 6))
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
hello
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
object Test {
|
||||
def f[T](xs: T*): T = xs.head
|
||||
def g[T] = f[T] _
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
println(g("hello" +: args))
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
hello
|
||||
|
|
@ -0,0 +1 @@
|
|||
-Yeta-expand-keeps-star
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
object Test {
|
||||
def f[T](xs: T*): T = xs.head
|
||||
def g[T] = f[T] _
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
println(g("hello"))
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue