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

Inconsistent handling of labeled and unlabeled tuples

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Won't Do
    • Component/s: Compiler
    • Labels:
    • Environment:

      Latest Swift version 3.0-dev

      Description

      Swift 3's type checker sometimes doesn't match tuples that have the right type but are missing labels for the values. This seems like a regression from Swift 2.2:

      struct MyDictionary<Key: Hashable, Value> { 
        typealias KeyValueTuple = (key: Key, value: Value) 
         
      #if swift(>=3.0)
        func foo<S: Sequence where S.Iterator.Element == KeyValueTuple>(s: S) {
          print(s) 
        } 
      #else
        func foo<S: SequenceType where S.Generator.Element == KeyValueTuple>(s: S) {
          print(s) 
        } 
      #endif
      } 
      
      let labeled = (key: "a", value: 1)
      let unlabeled = ("a", 1)
      
      let dictionary = MyDictionary<String, Int>()
      
      // These work in Swift 2.2 and 3.0
      dictionary.foo([(key: "a", value: 1)])
      dictionary.foo([("a", 1)])
      dictionary.foo([labeled])
      
      // This fails in Swift 3.0
      dictionary.foo([unlabeled])
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            nnnnnnnn Nate Cook
            Votes:
            1 Vote for this issue
            Watchers:
            10 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: