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

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
May 14, 2026, 7:30:48 PM (2 days ago) May 14
to Ian Chechin, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Dmitri Shuralyov, Dmitri Shuralyov, Hyang-Ah Hana Kim, golang...@luci-project-accounts.iam.gserviceaccount.com, Hajime Hoshi, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
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-by: Hyang-Ah Hana Kim <hya...@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmit...@google.com>
Auto-Submit: Hajime Hoshi <hajim...@gmail.com>
Reviewed-by: Hajime Hoshi <hajim...@gmail.com>
Files:
  • M bind/bind_test.go
  • M bind/genobjc.go
  • M bind/testdata/doc.objc.m.golden
Change size: M
Delta: 3 files changed, 65 insertions(+), 10 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: mobile
Gerrit-Branch: master
Gerrit-Change-Id: I5c0b1606fa7d3fb2de713e2c13e594ebc3f2ed4c
Gerrit-Change-Number: 777520
Gerrit-PatchSet: 6
Gerrit-Owner: Ian Chechin <ian00c...@gmail.com>
Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Hajime Hoshi <hajim...@gmail.com>
Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages