bind: align Objective-C setter selectors with sanitized property names

When gobind generates an Objective-C binding for a Go struct field or
package-level variable, the getter selector is derived through
objcNameReplacer(lowerFirst(name)) so that the resulting property
name avoids Objective-C reserved words and matches Cocoa conventions
for acronyms:

    Go field      ObjC property
    -----------   -------------
    OSName    ->  osName
    ID        ->  id_
    Init      ->  init_

The corresponding setter selector, however, was generated as
"set" + raw Go name. The two names then disagree, so calling
setSomething: via Swift's property assignment dispatch does not reach
the synthesized setter and stores written through the property are
silently dropped before they reach the Go-side accessor (the original
reproducer in the issue: a Go field named ID whose value never made
it back to Go after Swift assigned to dc.id_).

Extract objcGetterName for the existing objcNameReplacer(lowerFirst)
pipeline used to derive ObjC property and getter selectors, and add
objcSetterName that wraps it to produce the matching setter selector
(set + capitalize(getter)). Replace inline call sites in genobjc.go
with objcGetterName, and use objcSetterName at every setter-name call
site (package-level var setters in both the header and the
implementation, and instance-method setters on struct fields).

Update bind/testdata/doc.objc.m.golden to reflect the corrected
selector for the existing SF field (setSF -> setSf); no other golden
file is affected because the existing struct/variable test fixtures
do not contain acronyms or reserved-word names.

Adds bind.TestObjcPropertyName covering both helpers across normal,
acronym and reserved-word cases.

Fixes golang/go#76114.
Fixes golang/go#32008.

Change-Id: I5c0b1606fa7d3fb2de713e2c13e594ebc3f2ed4c
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/777520
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
3 files changed
tree: fc698c32ff1b5ecac9802a3741b192478c281fbc
  1. app/
  2. asset/
  3. bind/
  4. cmd/
  5. doc/
  6. event/
  7. example/
  8. exp/
  9. geom/
  10. gl/
  11. internal/
  12. testdata/
  13. .gitattributes
  14. .gitignore
  15. codereview.cfg
  16. CONTRIBUTING.md
  17. go.mod
  18. go.sum
  19. LICENSE
  20. PATENTS
  21. README.md
README.md

Go support for Mobile devices

Go Reference

The Go mobile repository holds packages and build tools for using Go on mobile platforms.

Package documentation as a starting point:

Caution image

The Go Mobile project is experimental. Use this at your own risk. While we are working hard to improve it, neither Google nor the Go team can provide end-user support.

This is early work and installing the build system requires Go 1.5. Follow the instructions on golang.org/wiki/Mobile to install the gomobile command, build the basic and the bind example apps.


Contributions to Go are appreciated. See https://go.dev/doc/contribute.

The git repository is https://go.googlesource.com/mobile.