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

Swift doesn't handle method families properly for renamed methods

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
    • Environment:

      Apple Swift version 4.0 (swiftlang-900.0.65 clang-900.0.37)
      Target: x86_64-apple-macosx10.9

      Description

      When using an @objc attribute to rename a method exposed to Obj-C, Swift doesn't handle method families properly.

      For example, if I have a method

      class Foo: NSObject {
          @objc static func new(foo: Int) -> Foo { … }
      }
      

      the generated Obj-C thunk will return a retained object, which is correct as this belongs to the new method family.

      However, if I write the following

      class Foo: NSObject {
          @objc(newWithFoo:)
          static func make(foo: Int) -> Foo { … }
      }
      

      the generated Obj-C thunk will return an autoreleased object.

      This could be fixed by adding the appropriate __attribute__((objc_method_family(none))) attribute to the method, but a far better fix would be to change the code that determines if it should be returning an owned or autoreleased object to consider the method family of the Obj-C selector rather than the Swift name of the method.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              Eridius Lily Ballard
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: