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

Pattern matching limited to var declarations, not allowed in assignments

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Misc Compiler
    • Labels:
      None

      Description

      Is pattern matching to variables only allowed during variable definitions, and not during var assignments?

      E.g., this works:
      val t = (1, 2)
      var (a, b) = t
      a = 1, b = 2

      But,
      var x = 10
      var y = 20
      (x, y) = t
      Illegal start of definitio

      Seems to be that pattern based assignment would also be quite useful???
      --------------------------------
      Further comments: (from Burak on the mailing list)
      This particular change would probably not require any changes to the matcher, rather to the frontend (parsing - desugaring - typechecking).

      It would be translated as something like

      var x = 10
      var y = 20
      <righthandside> match {
      (x1, y1) => x = x1; y = y1; <continuation>
      }

      The pattern matcher would never need to be aware of something being a mutable variable.

      Burak

        Activity

        Hide
        David R. MacIver added a comment -

        As per discussion on mailing list, this is actually pretty complicated, particularly when combined with syntax sugar for updates. It will need a SIP.

        Show
        David R. MacIver added a comment - As per discussion on mailing list, this is actually pretty complicated, particularly when combined with syntax sugar for updates. It will need a SIP.

          People

          • Assignee:
            David R. MacIver
            Reporter:
            johnmani
            TracCC:
            Seth Tisue
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development