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

Preserve availability on ObjC subscript getters and setters

    XMLWordPrintable

    Details

      Description

      @import Foundation;
      
      @interface DeprecatedGetter: NSObject
      - (id)objectAtIndexedSubscript:(NSInteger)i __attribute__((deprecated("bad getter")));
      - (void)setObject:(id)obj atIndexedSubscript:(NSInteger)i;
      @end
      
      @interface DeprecatedSetter: NSObject
      - (id)objectAtIndexedSubscript:(NSInteger)i;
      - (void)setObject:(id)obj atIndexedSubscript:(NSInteger)i __attribute__((deprecated("bad setter")));
      @end
      

      When the Objective-C code above is imported into Swift, the methods are mapped to a true subscript declaration. However, any availability attributes on the original methods are lost…or rather, the getter's availability is copied onto the subscript, but not the setter's.

      The relevant functions here are buildSubscriptGetterDecl and buildSubscriptSetterDecl in ClangImporter.cpp; these functions should call Impl.importAttributes to get the correct attributes for the getter and setter. We also need to figure out what's pulling the getter's availability onto the subscript; that's not really correct if the getter is deprecated but the setter is not.

      Tests for this would look something like https://github.com/apple/swift/commit/b0e12f4c80790364b7427af981e652f1c1c0da42#diff-348ce3800f609e6140007f774b227469R874.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Christopher Christopher Rogers
              Reporter:
              jrose Jordan Rose
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: