New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repeated parameter typed as T* rather than Seq[T] #4176
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4176?orig=1 |
@paulp said: |
@retronym said: There is some commented out code in the typechecker relevant to this problem. Looks like the Eta expansion used to prevented: As pf r12607, this check was commented out. The commit comment isn't illuminating -- #1269 is a For the benefit of future ticket readers, here's the problem without the REPL. If scalac followed the letter of the spec, E:\code\scratch\4176>cat 4176_1.scala
object test1 {
def id[A](as: A*) = as
val f = id[Int] _
}
E:\code\scratch\4176>cat 4176_2.scala
object test2 {
def main(args: Array[String]) {
val f = test1.f
f(1)
f(Nil: _*)
}
}
E:\code\scratch\4176>scalac -d out 4176_1.scala
E:\code\scratch\4176>scalac -classpath out -d out 4176_2.scala
E:\code\scratch\4176>scala -classpath out test2
E:\code\scratch\4176>scalac -classpath out -d out -Xprint:typer 4176_2.scala
[[syntax trees at end of typer]]// Scala source: 4176_2.scala
package <empty> {
final object test2 extends java.lang.Object with ScalaObject {
def this(): object test2 = {
test2.super.this();
()
};
def main(args: Array[String]): Unit = {
val f: (Int*) => Int* = test1.f;
f.apply(1);
{
f.apply((immutable.this.Nil: _*));
()
}
}
}
} |
@retronym said: |
@adriaanm said: I think adapt should turn repeated paramtypes into the corresponding type after uncurry since the spec says 'The type of such a repeated parameter inside the method is then the sequence type scala.Seq[T]'. I don't know what to derive from this concerning the type of the argument of the method and its eta-expansion since these are outside of the method, and the spec fragment talks about inside the method. |
@retronym said: |
@adriaanm said: Maybe we could deprecate it in 2.9? Re-assigning to scala meeting to re-open the discussion. |
@paulp said:
Tip from a seasoned, weathered, barely hanging on scala archaeologist: if the ticket number doesn't make any sense odds are it's in the pre-trac bug database, which is archived online. Here is #1269. http://lrytz.github.io/scala-aladdin-bugtracker/displayItem.do%3Fid=1269.html It was opened 8/8/07 and the commit is 8/21/07 and logic takes us the rest of the way. |
@odersky said: I'll change the inferred result type. But somebody else needs to follow up on the eta expansion, or we leave it as a won't fix. I simply do not have the bandwidth anymore to follow breakages in user code which will inevitably happen when we do this. |
@paulp said:
|
@paulp said: |
Commit Message Bot (anonymous) said: def id[T](xs: T*) = xs References #4176, leaving open pending resolution of eta expansion. |
@paulp said: |
Commit Message Bot (anonymous) said: (T*)U now eta-expands to Seq[T] => U, not T* => U. There is a -Yeta-expand-keeps-star Closes #4176, no review. |
@retronym said: Welcome to Scala version 2.10.0-20120504-065643-e52be82eef (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_31).
Type in expressions to have them evaluated.
Type :help for more information.
scala> def foo(a: String*) = a
foo: (a: String*)Seq[String]
scala> foo _
res0: Seq[String] => Seq[String] = <function1>
scala> (foo: Seq[String] => Seq[String])
<console>:9: error: type mismatch;
found : String* => Seq[String]
required: Seq[String] => Seq[String]
(foo: Seq[String] => Seq[String])
^ |
@retronym said: |
The first dose was scala/scala@bc4468c (where retronym's 771 was "a repeat dose"). For the record, aladdin is no longer archived online as shown. |
http://lrytz.github.io/scala-aladdin-bugtracker/displayBugs.do.html 🙂 |
=== What steps will reproduce the problem ===
=== What is the expected behavior? ===
According to the spec:
"4.6.2 Repeated Parameters
The last value parameter of a parameter section may be suffixed by “*”, e.g.
(..., x:T*).
The type of such a repeated parameter inside the method is then the sequence typescala.Seq[T]
"Firstly, the inferred type of
ids
should beSeq[A]
.Secondly, the eta expansion of
ids[Int] _
should result in(Seq[Int]) => Seq[Int])
=== What do you see instead? ===
The internal type of the repeated parameter leaks out; and, via eta expansion, results in a
Function1
withdef apply(v1: T*)
.=== Additional information ===
Such behaviour was explicitly excluded in #3652 and #3180.
=== What versions of the following are you using? ===
The text was updated successfully, but these errors were encountered: