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

bind: fix Objective-C code for struct field name with uppercase prefix #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

xudongzheng
Copy link

Objective-C code generated by gobind does not correct set a struct field whose name has an upper case prefix. This includes struct fields with names such as URL, ID, etc.

Consider the following Go code:

package example

type S struct {
        BRAVO string
}

func Test(s *S) string {
        return s.BRAVO
}

Generate bindings with gomobile bind -target ios example.

Use the following code for iOS:

let s = ExampleS()
s.bravo = "example"
print("result", ExampleTest(s))

The output is "result" rather than "result example".

The current gobind generates:

- (void)setBRAVO:(NSString* _Nonnull)v {
        int32_t refnum = go_seq_go_to_refnum(self._ref);
        nstring _v = go_seq_from_objc_string(v);
        proxyexample_S_BRAVO_Set(refnum, _v);
}

It should instead generate

- (void)setBravo:(NSString* _Nonnull)v {
        int32_t refnum = go_seq_go_to_refnum(self._ref);
        nstring _v = go_seq_from_objc_string(v);
        proxyexample_S_BRAVO_Set(refnum, _v);
}

This pull request fixes this for struct fields. This also makes the change for package's top level variables for consistency.

The same problem doesn't exist for Java/Android.

@gopherbot
Copy link
Contributor

This PR (HEAD: 9935c16) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/mobile/+/240009 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants