Skip to content

objc: skip methods whose selector isn't a valid Rust identifier - #3546

Open
HawkForge wants to merge 1 commit into
rust-lang:mainfrom
HawkForge:fix/objc-dollar-selector
Open

HawkForge wants to merge 1 commit into
rust-lang:mainfrom
HawkForge:fix/objc-dollar-selector

Conversation

@HawkForge

Copy link
Copy Markdown

Fixes #3483

bindgen panicked with "take$foo" is not a valid Ident on an Objective-C method whose selector contains $, e.g. - (int)take$foo:(int)t;. ObjCMethod::format_method_call turns each selector part into a proc_macro2::Ident for msg_send!, and $ is legal in ObjC selectors but not in Rust identifiers.

Mangling $ to _ like we do for C identifiers would be wrong here: msg_send! builds the selector from the identifier tokens, so the generated code would send take_foo: instead of take$foo:. Since the selector can't be spelled, format_method_call now warns and returns None for such methods, the same way it already does for C-style parameter mismatches. The other methods of the interface are still generated.

Test: added objc_selector_dollar.h with expectations. It has a $ in the first and in a later selector part, plus a normal method that must still be generated. Before the change the repro header panicked; after it the CLI succeeds.

cargo test -p bindgen-tests passes except header_objc_template_h, which also fails on unmodified main. cargo +nightly fmt --check is clean.

Selectors may contain `$`, which can't be an Ident, so format_method_call
panicked. msg_send! builds the selector from identifier tokens, so mangling
`$` would silently send a different selector. Warn and skip the method
instead, like the C-style parameter case.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ObjC selector with $ panics ("take$foo" is not a valid Ident)

1 participant