Uploaded image for project: 'Swift'
  1. Swift
  2. SR-1692

Custom prefix/postfix increment/decrement operators fail

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
    • Environment:

      Swift 3 on OS X and Linux

      Description

      Although ++ is removed from the language, you'd think you could add it back in

      // THIS WORKS
      prefix operator ++* {}
      prefix public func ++* <T: Integer>( x: inout T) -> T {
          x = x + 1; return x
      }
      
      // THIS DOESN'T WORK
      prefix operator ++ {}
      prefix public func ++ <T: Integer>( x: inout T) -> T {
          x = x + 1; return x
      }
      
      var x = 5
      print(++*x)
      print(++x) // fail
      
      Error: <unknown>:0: error: build had 1 command failures
      swift-build: error: exit(1): /usr/bin/swift-build-tool -f /swift-execution/.build/debug.yaml
      ERROR at line 15, col 7: '++' is unavailable: it has been removed in Swift 3
      print(++x) // fail
            ^~
      Swift.++:3:20: note: '++' has been explicitly marked unavailable here
      prefix public func ++(x: inout Int) -> Int

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            erica erica sadun
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: