-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
Conversation
@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
73cfb77
to
0a37a5d
Compare
@swift-ci please smoke test |
let param = e.with(\.type, (argTypes[i] ?? e.type)!) | ||
let name = param.secondName ?? param.firstName | ||
if name.trimmed.text == "_" { |
There was a problem hiding this comment.
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 _
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good point!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait no that redundancy is actually an error:
| `- note: in expansion of macro '_SwiftifyImport' on global function 'ptrNamed(ptr:_:)' here
6 | func ptrNamed(ptr: UnsafePointer<CInt>, _ len: CInt) {
7 | }
+--- macro expansion @_SwiftifyImport -------------------------------
|1 | @_alwaysEmitIntoClient
|2 | func ptrNamed(ptr ptr: UnsafeBufferPointer<CInt>) {
| | `- error: extraneous duplicate parameter name; 'ptr' already has an argument label
|3 | return unsafe ptrNamed(ptr: ptr.baseAddress!, CInt(exactly: ptr.count)!)
|4 | }
+--------------------------------------------------------------------
I don't know of any way a C function can import to that syntax, but it doesn't hurt to handle it correctly.
_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 (cherry picked from commit 8e27947)
_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