dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
157 stars 46 forks source link

[swift2objc] Support properties that throw #1765

Open liamappelbe opened 6 days ago

liamappelbe commented 6 days ago

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.

abhishekpawar1060 commented 5 days ago

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

liamappelbe commented 3 days ago

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 commented 3 days ago

Oh, btw, this was a follow up bug to https://github.com/dart-lang/native/pull/1766, so make sure to sync past that now that it's landed, since it takes care of the parsing side of throws.