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] Add support for mutating functions #1944

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nikeokoronkwo
Copy link
Contributor

Fixes #1737

The changes here address support for mutating functions.
Not much needs to be done in the transformation end, as mutating functions are only allowed on structs and protocols.

@nikeokoronkwo nikeokoronkwo changed the title added support for mutating functions [swift2objc] Add support for mutating functions Jan 27, 2025
@nikeokoronkwo nikeokoronkwo marked this pull request as ready for review January 27, 2025 14:36
Copy link

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbols
License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/jni/lib/src/third_party/generated_bindings.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

Copy link
Contributor

@liamappelbe liamappelbe left a comment

Choose a reason for hiding this comment

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

Needs formatting.

@@ -140,16 +141,14 @@ ParsedFunctionInfo parseFunctionInfo(
params: parameters,
throws: annotations.contains('throws'),
async: annotations.contains('async'),
mutating: declarationFragments
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that the check is in here, you can make it more specific. If a mutating keyword appears anywhere in the function declaration, this will mark the entire function as mutating. It might be the case that there it's not syntactically valid for mutating to appear anywhere else, but I don't know that's true, and it might not be true in future.

See the chunk of code that checks for annotations? You can copy it to the start of this function and use it to check for annotations that come before the (, replacing the final openParen = tokens.indexWhere( stuff, and store them in a prefixAnnotations set or something. Better yet, factor out that chunk of code into a separate function that prefixAnnotations and annotations both use.

Then this line becomes mutating: prefixAnnotations.contains('mutating'),.

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.

[swift2objc] Support mutating methods
2 participants