Skip to content
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

[swift2objc] Support properties that throw #1765

Open
liamappelbe opened this issue Nov 29, 2024 · 6 comments · May be fixed by #1939
Open

[swift2objc] Support properties that throw #1765

liamappelbe opened this issue Nov 29, 2024 · 6 comments · May be fixed by #1939
Labels
good first issue A good starting issue for contributors (issues with this label will appear in /contribute) package:swift2objc

Comments

@liamappelbe
Copy link
Contributor

liamappelbe commented Nov 29, 2024

Getters are allowed to throw in Swift:

public class MyClass {
  public var myProperty: MyClass {
    get throws { ... }
  }
}

public var globalVar: MyClass {
  get throws { ... }
}

Such properties must be read-only (they can't have setters).

Translating these to an @objc compatible wrapper looks like this:

@objc public class MyClassWrapper: NSObject {
  var wrappedInstance: MyClass

  @objc public var myProperty: MyClassWrapper {
    get throws {
      try MyClassWrapper(wrappedInstance.myProperty)
    }
  }
}

But this is a compile error because throwing getters aren't allowed to be annotated with @objc. The fix is to instead translate throwing getters to ordinary methods.

@liamappelbe liamappelbe moved this to Backlog in ObjC/Swift interop Nov 29, 2024
@liamappelbe liamappelbe added the good first issue A good starting issue for contributors (issues with this label will appear in /contribute) label Nov 29, 2024
@abhishekpawar1060
Copy link

I would like to work on this issue, should I work on this issue?

@liamappelbe
Copy link
Contributor Author

Sure. PRs are welcome. I think most of the changes for this fix will be in the transformation stage, so a good place to start reading would be transform.dart. Make sure to add a test case to test/integration. Let me know if you have any questions.

@liamappelbe
Copy link
Contributor Author

Oh, btw, this was a follow up bug to #1766, so make sure to sync past that now that it's landed, since it takes care of the parsing side of throws.

@AmrAhmed119
Copy link

Hi @liamappelbe, I would like to contribute to this issue. If the other contributor is no longer actively working on it, Please let me know if I can proceed.

@liamappelbe
Copy link
Contributor Author

@AmrAhmed119 sure, go for it :)

@AmrAhmed119 AmrAhmed119 linked a pull request Jan 24, 2025 that will close this issue
1 task
@AmrAhmed119
Copy link

Hi @liamappelbe, I've created a pull request for this issue, looking forward for your review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue A good starting issue for contributors (issues with this label will appear in /contribute) package:swift2objc
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

3 participants