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

Subclasses of generic classes don't remember @objc names for optional protocol methods

    XMLWordPrintable

    Details

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

      macOS Mojave, both in Swift 4.2 and the 2018-12-09 5.0 snapshot.

      Description

      I need to manually specify @objc names for optional methods in a protocol implemented by a generic superclass.

      Example:

      import Foundation
      
      @objc protocol P {
          @objc(doF) optional func f() -> Int
      }
      
      class Gen<T>: NSObject, P {}
      class NoGen:  NSObject, P {}
      
      class NoGen1: NoGen {
          func f() -> Int {
              return 42
          }
      }
      (NoGen1() as P).f?() // 42, works
      
      class Gen1: Gen<Any> {
          func f() -> Int {
              return 42
          }
      }
      (Gen1() as P).f?() // nil <----------
      
      class Gen2: Gen<Any> {
          @objc(doF) func f() -> Int { // explicitly set objc name
              return 42
          }
      }
      (Gen2() as P).f?() // 42, works again
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ahti Lukas Stabe
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: