Skip to content
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

[swift2objc] Support unlabeled parameters #1756

Merged
merged 1 commit into from
Nov 27, 2024
Merged

[swift2objc] Support unlabeled parameters #1756

merged 1 commit into from
Nov 27, 2024

Conversation

liamappelbe
Copy link
Contributor

@liamappelbe liamappelbe commented Nov 27, 2024

Swift function params have both an internal name (used inside the function), and an external label (used like a Dart named parameter when invoking the function). Either one, but not both, can be omitted. If the internal name is omitted, then the external label is also the internal name. If the external label is omitted (or rather, set to _), then the parameter is invoked like a Dart positional param.

public foo(label1 name1: Int, label2: Int, _ name3: Int) {
  // In here we have name1, label2, and name3.
}

foo(label1: 123, label2: 456, 789);
  • On the parsing side, we supported these cases for initializers but not functions/methods. I've unified the parsing logic by renaming/moving parseInitializerParams to parseFunctionParams.
    • This function is unchanged except that function declaration fragments can end with -> ReturnType. So the check at the end of parsing has to allow that case.
  • On the codegen side, the initializer/function/method signatures were generating correctly, but the way we were invoking the wrapped function was incorrect
    • I factored out the invocation stuff into generateInvocationParams, and fixed the bug by checking if the label is _.

@coveralls
Copy link

Coverage Status

coverage: 88.828% (-0.01%) from 88.84%
when pulling c44a575 on anonparam
into 071dcf3 on main.

@liamappelbe liamappelbe changed the title WIP: [swift2objc] Support unlabeled parameters [swift2objc] Support unlabeled parameters Nov 27, 2024
@liamappelbe liamappelbe marked this pull request as ready for review November 27, 2024 00:30
@liamappelbe liamappelbe merged commit 70e83a9 into main Nov 27, 2024
6 checks passed
@liamappelbe liamappelbe deleted the anonparam branch November 27, 2024 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants