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

Protocol compositions: improve composing diagnostics

    XMLWordPrintable

    Details

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

      Xcode 9.2, Xcode 9.3 (9E145), Xcode 9.4 beta

      Description

      Although apparently they aren't harmful, in Xcode 9.4 (Swift 4.1) the following cases do not produce warnings. Some of them do produce warnings in Xcode 9.2 (Swift 4) together with the error "Protocol-constrained type is neither allowed nor needed here". I suggest to show warnings in all these cases: 

      protocol Foo {}
      protocol Fooo: Foo {}
      
      class A: Foo {}
      
      protocol Soo1: Foo & Foo {} 
      // Xcode 9.2:  
      //     error: Duplicate inheritance from 'Foo'
      //     error: Protocol-constrained type is neither allowed nor needed here
      //     warning: Redundant conformance constraint 'Self: Foo'
      // 
      // Xcode 9.4 beta: Nothing
      //
      // Suggested warning: Duplicate inheritance from 'Foo'
      
      
      protocol Soo2: Foo & Fooo {}
      // Xcode 9.2:  
      //     error: Protocol-constrained type is neither allowed nor needed here
      //     warning: Redundant conformance constraint 'Self: Foo'
      //
      // Xcode 9.4 beta: Nothing
      //
      // Suggested warning: Redundant conformance constraint 'Self: Foo' 
      
      
      
      // Xcode 9.2 & Xcode 9.4 beta: Nothing
      
      func foo1(_ arg: A & Foo) {} 
      // Suggested warning:
      // Redundant conformance of protocol-constrained type (or existential type) to 'Foo'  
      
      func foo2(_ arg: A & A) {} 
      // Suggested warning:
      // Protocol-constrained type (or existential type) already contains class 'A'  
      
      func foo3(_ arg: Foo & Foo) {} 
      // Suggested warning:
      // Redundant conformance of protocol-constrained type (or existential type) to 'Foo' [or]  Protocol-constrained type (or existential type) already contains protocol 'Foo'  
      
      func foo4(_ arg: Fooo & Foo) {} 
      // Suggested warning:
      // Redundant conformance of protocol-constrained type (or existential type) to 'Foo'

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              anthonylatsis Anthony Latsis
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated: