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
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