Scala Programming Language
  1. Scala Programming Language
  2. SI-4176

Repeated parameter typed as T* rather than Seq[T]

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.0-M1
    • Component/s: Misc Compiler
    • Labels:
      None
    • Environment:

      repeated

      Description

      === What steps will reproduce the problem ===

      scala> def id[A](as: A*) = as
      id: [A](as: A*)A*
      
      scala> id[Int] _
      res12: (Int*) => Int* = <function1>
      
      scala> res12(1) 
      res13: Int* = WrappedArray(1)
      
      scala> res12(Nil :_*)
      res14: Int* = List()
      

      === 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 type `scala.Seq[T]`"

      Firstly, the inferred type of `ids` should be `Seq[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` with `def apply(v1: T*)`.

      === Additional information ===

      Such behaviour was explicitly excluded in SI-3652 and SI-3180.

      === What versions of the following are you using? ===

      • Scala: 2.8.1

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          Going to make it Seq[A] => Seq[A] and leave an option to A* it just in case.

          Show
          Paul Phillips added a comment - Going to make it Seq [A] => Seq [A] and leave an option to A* it just in case.
          Hide
          Commit Message Bot added a comment -

          (extempore in r25809) 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.

          Show
          Commit Message Bot added a comment - (extempore in r25809 ) 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.
          Hide
          Jason Zaugg added a comment -
          
          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])
                         ^
          
          Show
          Jason Zaugg added a comment - 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]) ^
          Show
          Jason Zaugg added a comment - WIP: https://github.com/retronym/scala/compare/ticket/4176
          Show
          Jason Zaugg added a comment - https://github.com/scala/scala/pull/771

            People

            • Assignee:
              Jason Zaugg
              Reporter:
              Jason Zaugg
              TracCC:
              Ismael Juma, Paul Phillips
            • Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development