-
Notifications
You must be signed in to change notification settings - Fork 56
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
base: main
Are you sure you want to change the base?
Conversation
mutating
functionsmutating
functions
PR HealthBreaking changes ✔️
Changelog Entry ✔️
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.
License Headers ✔️
All source files should start with a license header. Unrelated files missing license headers
|
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.
Needs formatting.
pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_function_declaration.dart
Outdated
Show resolved
Hide resolved
@@ -140,16 +141,14 @@ ParsedFunctionInfo parseFunctionInfo( | |||
params: parameters, | |||
throws: annotations.contains('throws'), | |||
async: annotations.contains('async'), | |||
mutating: declarationFragments |
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.
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'),
.
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.