Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Swiftify] Handle anonymous parameters #81384

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

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

Conversation

hnrklssn
Copy link
Contributor

@hnrklssn hnrklssn commented May 8, 2025

_SwiftifyImport would expand with syntax errors if applied to a function with anonymous parameters, because it would try to refer to parameters using the name _. Detect these cases and create names for unnamed parameters.

rdar://150955944

@hnrklssn
Copy link
Contributor Author

hnrklssn commented May 8, 2025

@swift-ci please smoke test

_SwiftifyImport would expand with syntax errors if applied to a function
with anonymous parameters, because it would try to refer to parameters
using the name `_`. Detect these cases and create names for unnamed
parameters.

rdar://150955944
@hnrklssn hnrklssn force-pushed the swiftify-anonymous-params branch from 73cfb77 to 0a37a5d Compare May 9, 2025 00:13
@hnrklssn
Copy link
Contributor Author

hnrklssn commented May 9, 2025

@swift-ci please smoke test

Comment on lines +430 to +432
let param = e.with(\.type, (argTypes[i] ?? e.type)!)
let name = param.secondName ?? param.firstName
if name.trimmed.text == "_" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the redundant logic to extract the parameter name and check for _?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this is needed for general swift syntax, e.g. if you have func foo(bar: T). If you just blindly do .with(\.secondName, getParamName(param, i)), then you end up with func foo(bar bar: T)). Which I guess is not actually a problem, just redundant. But I also don't think we can end up with that syntax from an imported C function, so that's fine.

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.

2 participants