Skip to content

Implement correct NS_OPTIONS type import inside objc interface (5.9) #67130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

plotfi
Copy link
Contributor

@plotfi plotfi commented Jul 5, 2023

This this PR refactors a code pattern to check for an NS_OPTIONS type inside a RecordDecl etc, and reuses the check to also ensure that NS_OPTIONS types used inside of ObjC interfaces. The failing code example happened with assigning a UIKit UISwipeGestureRecognizer Direction type:

import UIKit

public func foo(gesture: UISwipeGestureRecognizer, direction: UISwipeGestureRecognizer.Direction) {
  gesture.direction = direction // error
}

Release Branch Checklist:

  • Explanation: This this PR refactors a code pattern to check for an NS_OPTIONS type inside a RecordDecl etc, and reuses the check to also ensure that NS_OPTIONS types used inside of ObjC interfaces as property or method types are also properly imported with the correct type in the presents of C++-interop.
  • Scope: C++-Interop NS_OPTIONS type import inside of ObjC @interface property getters/setters.
  • Issue: None filed externally, used code example from above from internal bug report.
  • Risk: low, only triggers if attribute unavailable+anonymous enum pattern is followed, same as existing patches already landed.
  • Testing: lit test, checks that correct type name is used in the ObjC class as it is in the C/C++ struct.
  • Reviewer: @hyp @zoecarver @NuriAmari @DougGregor

plotfi added 3 commits July 5, 2023 15:30
… reusable.

Zoe did a nice fix on swiftlang#66452
that I would like to reuse for ObjCPropertyDecl field types in
importObjCPropertyDecl as well. This will fix cases such as:

```
import UIKit

func f(gesture: UISwipeGestureRecognizer,
       direction: UISwipeGestureRecognizer.Direction) {
  gesture.direction = direction // error
}
```

because it will make sure the field inside class UIGestureRecognizer is
of the enum-struct type and not the typedef-rawValue type when importing
an ObjC class.

(cherry picked from commit ec5b7b0)
…uct type

Try importing ObjCPropertyDecl field types the C++-Interop-NS_OPTIONS
way. This will fix cases such as:

```
import UIKit

func f(gesture: UISwipeGestureRecognizer,
       direction: UISwipeGestureRecognizer.Direction) {
  gesture.direction = direction // error
}
```

because it will make sure the field inside class UIGestureRecognizer is
of the enum-struct type and not the typedef-rawValue type when importing
an ObjC class.

(cherry picked from commit 7cef628)
Add-on to address comments from swiftlang#67036

Addresses some nits, test addons, and some code cleanups/improvement.

(cherry picked from commit 9369908)
@plotfi plotfi added the c++ interop Feature: Interoperability with C++ label Jul 5, 2023
@plotfi plotfi requested a review from a team as a code owner July 5, 2023 19:42
@plotfi plotfi changed the title Implement correct NS_OPTIONS type import inside objc interface Implement correct NS_OPTIONS type import inside objc interface (5.9) Jul 5, 2023
@DougGregor
Copy link
Member

@swift-ci please test

@plotfi plotfi merged commit 8b182fb into swiftlang:release/5.9 Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants