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

Lack of associatedType namespacing leads to surprising errors

    XMLWordPrintable

    Details

      Description

      When an entity adopts from two protocols that share an associatedType, surprising errors result from namespacing issues.

      protocol A {
          associatedtype T
          var aT: T { get }
      }
      
      protocol B {
          associatedtype T
          var bT: T { get }
      }
      

      Type C does not conform to protocol 'B'.

      class C: A, B {
          var aT = String()
          var bT = Int()
      }
      

      Compiles without error.

      class C: A, B {
          var aT = String()
          var bT = String()
      }
      

      Type C does not conform to protocol 'A'.

      class C: A, B {
          typealias T = Int
          var aT = String()
          var bT = Int()
      }
      

      I would offer that I consider this a low priority or trivial issue, but undesirable behavior nonetheless.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              nblake Noah Blake
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: