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

A possible tuple-inference/parameter-resolution bug in Swift 3.0.1

    Details

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

      XCode Version 8.2.1 (8C1002), MacOS 10.12.3 (16D32)

      Description

      The following code compiles and yields somewhat unexpected results.

      func test<T>(_ a: T) -> String
      {
        return String(describing: type(of: T.self))
      }
      
      var int = test(1)
      var odd = test(1, 2)
      var tuple = test((1, 2))
      var labels = test(a: 1, b: 2)
      var nestedTuple = test(((1, 2)))
      var complexTuple = test((1, (2, 3)))
      

      Here are the results in the Playground:

      With argument label looks fine:

      Without argument label seems strange:

      • odd: Swift interpreted the two parameters as a Tuple. Is that correct, though? Are the parentheses allowed to serve double-duty both as part of the function-call expression and as part of the tuple expression?
      • labels: The issue with double-duty parentheses isn’t limited to anonymous tuples. The compiler treats what looks like two labeled function-call parameters as a tuple with two Ints labeled {a:}

        and

        {b:}

        .

      • nestedTuple: This is not a tuple of a tuple, but just a two-element tuple

      I wrote up more details on my blog before I discovered that this issue-tracker for Swift.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              mvonballmo Marco von Ballmoos
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: