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

Syntactic sugar for calling mutator doesn't always work

    Details

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

      Description

      === What steps will reproduce the problem (please be specific and use wikiformatting)? ===

        (new { def field = 0; def field_=(i: Int) = () }).field = 5 // compiles as expected
        (new { def field(implicit i: Int) = 0; def field_=(i: Int) = () }).field = 5 // compiles even with implicit params on getter
        (new { def field = 0; def field_=[T](i: Int) = () }).field = 5 // compiles with type param on setter
        (new { def field[T] = 0; def field_=(i: Int) = () }).field = 5 // DOESN'T COMPILE
      

      === What is the expected behavior? ===
      According to the standard, "If x is a parameterless function defined in some template, and the same template contains a setter function x_= as member, then the assignment x = e is interpreted as the invocation x_=(e) of that setter function. Analogously, an assignment f .x = e to a parameterless function x is interpreted as the invocation f.x_=(e)".

      I would expect the fourth case to compile as the getter has no parameters.
      If I'm allowed to add type parameters to the setter and it still works, I'd expect to be able to add type parameters to the getter as well.

      === What do you see instead? ===
      The fourth case doesn't compile and fails with "error: reassignment to val".

      === Additional information ===
      Bug is possibly in method typedAssign in Typers.scala

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

      • Scala: 2.8.1
      • Java: 1.6.0_22
      • Operating system: Mac OS X 10.6.6

        Activity

        Hide
        Adriaan Moors added a comment -

        the spec language means that the type parameter case should work as well, so it's a bug

        Show
        Adriaan Moors added a comment - the spec language means that the type parameter case should work as well, so it's a bug
        Hide
        Commit Message Bot added a comment -

        (extempore in r25048) A getter with type params is still a getter. Closes #4237.
        There were two distinct bugs in here, which if I ran the world
        would be a wakeup call that robust software cannot emerge from
        thousands of lines of low-level AST matching. In case you are
        frozen in suspense: I do not run the world. Review by moors.

        Show
        Commit Message Bot added a comment - (extempore in r25048 ) A getter with type params is still a getter. Closes #4237. There were two distinct bugs in here, which if I ran the world would be a wakeup call that robust software cannot emerge from thousands of lines of low-level AST matching. In case you are frozen in suspense: I do not run the world. Review by moors.

          People

          • Assignee:
            Adriaan Moors
            Reporter:
            Jean-Philippe Pellet
            TracCC:
            Ismael Juma, Seth Tisue
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development