fix: Add attribute nonnull_error if returning pointer and error from Objective-C#82
fix: Add attribute nonnull_error if returning pointer and error from Objective-C#82jefft0 wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
92b5fb7 to
e9ab6b9
Compare
|
This PR (HEAD: e9ab6b9) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/mobile/+/426595 to see it. Tip: You can toggle comments from me using the |
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be Please don’t reply on this GitHub thread. Visit golang.org/cl/426595. |
Signed-off-by: jefft0 <jefft0@gmail.com>
e9ab6b9 to
b50c057
Compare
|
This PR (HEAD: b50c057) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/mobile/+/426595 to see it. Tip: You can toggle comments from me using the |
Consider the following Go code with a method that returns a byte array and an error:
gobind creates an Objective-C method which returns
NSData*and an error:The method signature seen by Swift is
func getData() throws -> Data. The problem is thatDatais not optional, and when the Objective-C method returns NULL the program crashes. This is the default signature as explained in the Swift documentation: https://clang.llvm.org/docs/AttributeReference.html#swift-errorBut this is not appropriate for gobind since it is valid for Go to return a nil value. We don't want the crash. This pull request updates
asSignatureso that if the method returns an error and the method returns a nullable pointer toNSDataorNSString, then add thenonnull_errorattribute as explained in the Swift documentation.With this attribute, the method signature seen by Swift is
func getData() throws -> Data?. When the Go function returns nil, it is returned as a nil optional value without crashing.