-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
x/mobile: Exported structs not retaining field values in Swift #32008
Comments
I've created the following repo to reproduce the issue: |
I think I've found the issue, essentialy when binding the framework with the following command:
If we - (NSString* _Nonnull)osName {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring r0 = proxymobile_Config_OSName_Get(refnum);
NSString *_r0 = go_seq_to_objc_string(r0);
return _r0;
}
- (void)setOSName:(NSString* _Nonnull)v {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring _v = go_seq_from_objc_string(v);
proxymobile_Config_OSName_Set(refnum, _v);
} Whereas the - (NSString* _Nonnull)label {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring r0 = proxymobile_Config_Label_Get(refnum);
NSString *_r0 = go_seq_to_objc_string(r0);
return _r0;
}
- (void)setLabel:(NSString* _Nonnull)v {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring _v = go_seq_from_objc_string(v);
proxymobile_Config_Label_Set(refnum, _v);
} |
I've updated the repo that reproduces this issue: If the following patch is applied to golang/mobile@master...triztian:issue/32008 then we reinitialize:
The executable behaves as expected, i.e. I get the following:
The generated accessors after applying the patch are the following: - (NSString* _Nonnull)label {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring r0 = proxymobile_Config_Label_Get(refnum);
NSString *_r0 = go_seq_to_objc_string(r0);
return _r0;
}
- (void)setLabel:(NSString* _Nonnull)v {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring _v = go_seq_from_objc_string(v);
proxymobile_Config_Label_Set(refnum, _v);
}
- (NSString* _Nonnull)osName {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring r0 = proxymobile_Config_OSName_Get(refnum);
NSString *_r0 = go_seq_to_objc_string(r0);
return _r0;
}
- (void)setOsName:(NSString* _Nonnull)v {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring _v = go_seq_from_objc_string(v);
proxymobile_Config_OSName_Set(refnum, _v);
} I'd create a PR but if I run the - (NSString* _Nonnull)sf {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring r0 = proxydoc_S_SF_Get(refnum);
NSString *_r0 = go_seq_to_objc_string(r0);
return _r0;
}
- (void)setSF:(NSString* _Nonnull)v {
int32_t refnum = go_seq_go_to_refnum(self._ref);
nstring _v = go_seq_from_objc_string(v);
proxydoc_S_SF_Set(refnum, _v);
} I found the capitalization rules here: @eliasnaur what should I do to create an PR that is acceptable, is there a specific process to update the golden files? I think this will affect anyone that follows the naming guidelines for acronyms and is an issue that manifests silently. |
You can update the golden files with go test ./bind -update |
Thank you for the quick reply, I've done that and it seems to have fixed the tests:
I've submitted a PR here: |
The generation for getters and setters of Go exported fields that followed the accroynyms rule, i.e. for a field named `OSName` the resulting getter and settere were `osName` and `setOSName` respectively, however the Obj-C rules defined here: * https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html expected for the names to be the following: `osName` and `setOsName`. This commit updates setter name generation by capitalizing the field name and leaves the getter name unchaged, this also updates the golden files. Fixes golang/go#32008
The generation for getters and setters of Go exported fields that followed the accroynyms rule, i.e. for a field named `OSName` the resulting getter and settere were `osName` and `setOSName` respectively, however the Obj-C rules defined here: * https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html expected for the names to be the following: `osName` and `setOsName`. This commit updates setter name generation by capitalizing the field name and leaves the getter name unchaged, this also updates the golden files. Fix golang/go#32008
Change https://golang.org/cl/186978 mentions this issue: |
The generation for getters and setters of Go exported fields that followed the acronyms rule, i.e. for a field named `OSName` the resulting getter and setter were `osName` and `setOSName` respectively, however the Obj-C rules defined here: * https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html expected for the names to be the following: `osName` and `setOsName`. This commit updates setter name generation by capitalizing the first char and lower casing the second one, it leaves the getter name unchaged, this also updates the golden files. Fix golang/go#32008
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Haven't tested
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I'm using the latest
gomobile
, installed from this commit:In my go source, I added a struct type that is exposed as part of Gomobile:
In the Swift code I use the following to create an instance and set some fields.
I build the framework like so:
What did you expect to see?
I expected to see the
config
variable retain the assigned string values in the swift code.What did you see instead?
The
config
variable not retaining the swift values, for example take a look at this debugger capture:The text was updated successfully, but these errors were encountered: