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

Don't allow swapping a single-tuple function with a multiple-argument function

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
      None

      Description

      Swift should properly distinguish between single-tuple and multiple-argument function types.
      But it isn't, as demonstrated below.
      The following is the behavior of swift-DEVELOPMENT-SNAPSHOT-2017-06-05-a-osx (-swift-version 4):

      func f(_ a: Int, _ b: Int) { print("\(a), \(b)") }
      func g(_ tuple: (Int, Int)) { print("\(tuple)") }
      f(1, 2) // 1, 2
      g((1, 2)) // (1, 2)
      // Working as expected.
      
      // But (pay close attention):
      var (fCopy, gCopy) = (f, g)
      fCopy(1, 2) // 1, 2
      gCopy((1, 2)) // (1, 2)
      swap(&fCopy, &gCopy)
      fCopy(1, 2) // (1, 2)
      gCopy((1, 2)) // 1, 2
      // I would not expect that call to swap to compile,
      // since the type parameter of swap<T> can't be both
      // (Int, Int) -> () and
      // ((Int, Int)) -> ().
      // And also note the last two lines, where fCopy is
      // actually calling g, printing its two args as a
      // tuple, and gCopy actually calling f, printing its
      // single tuple as two separate args.
      

      (Reported as requested by Mark Lacey here:
      https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170605/037013.html
      )

        Attachments

          Activity

            People

            Assignee:
            rudkx Mark Lacey
            Reporter:
            jens Jens Persson
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: