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

case class copy method should not be currying - Scala 2.10.0-M4

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.0-M4
    • Component/s: None
    • Labels:
      None

      Description

      I believe the following code is wrong:

      case class C(i: Int)(implicit m: Int) { def inc = copy(i = i+1) } 
      >defined class C
      
      implicit val n = 1
      >n: Int = 1
      
      scala> C(0)
      res1: C = C(0)
      
      scala> res1.inc
      res2: Int => C = <function1>
      

      res2 should be a new instance of `C`

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          Well yeah, the non-implicit second parameter list is the whole reason we did it in the first place. It's an error on purpose.

          Show
          Paul Phillips added a comment - Well yeah, the non-implicit second parameter list is the whole reason we did it in the first place. It's an error on purpose.
          Hide
          Paul Phillips added a comment -

          Injecting my comment from the scala-internals thread because it seems plausibly among the least bad ways to go from here.

          Hmm, maybe we should let people declare the copy signature they want, and accommodate it if possible.
          
          case class C(x: Int)(y: Int)(implicit z: Int) {
            def copy(x: Int = x)(y: Int = y): C  // this way z is fixed at construction, and gets a field
            def copy(x: Int = x)(y: Int = y)(implicit z: Int = z): C // this way z is an optional implicit, and gets a field
            def copy(x: Int = x)(y: Int = y)(implicit z: Int): C // this way z is a mandatory implicit, no field
            def copy(x: Int = x)(y: Int)(implicit z: Int): C // and this way neither y nor z gets a field
          }
          
          Show
          Paul Phillips added a comment - Injecting my comment from the scala-internals thread because it seems plausibly among the least bad ways to go from here. Hmm, maybe we should let people declare the copy signature they want, and accommodate it if possible. case class C(x: Int)(y: Int)(implicit z: Int) { def copy(x: Int = x)(y: Int = y): C // this way z is fixed at construction, and gets a field def copy(x: Int = x)(y: Int = y)(implicit z: Int = z): C // this way z is an optional implicit, and gets a field def copy(x: Int = x)(y: Int = y)(implicit z: Int): C // this way z is a mandatory implicit, no field def copy(x: Int = x)(y: Int)(implicit z: Int): C // and this way neither y nor z gets a field }
          Hide
          Ryan Hendrickson added a comment -

          Ah, sorry, didn't realize there was an intended spec change here. Is there a thread or something to which someone could point me that explains why this is a desirable change?

          Show
          Ryan Hendrickson added a comment - Ah, sorry, didn't realize there was an intended spec change here. Is there a thread or something to which someone could point me that explains why this is a desirable change?
          Hide
          Paul Phillips added a comment -
          Show
          Paul Phillips added a comment - SI-5009
          Show
          Lukas Rytz added a comment - fixed in https://github.com/scala/scala/commit/6c7f2b6460de1aa6d15a6005921ca50e98a54027

            People

            • Assignee:
              Lukas Rytz
              Reporter:
              Eric Torreborre
            • Votes:
              1 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development