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
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class MethodDeclaration

bool isStatic;

bool mutating;

String get fullName => [
name,
for (final p in params) p.name,
Expand All @@ -61,5 +63,6 @@ class MethodDeclaration
this.isOverriding = false,
this.throws = false,
this.async = false,
this.mutating = false
}) : assert(!isStatic || !isOverriding);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ MethodDeclaration parseMethodDeclaration(
isStatic: isStatic,
throws: info.throws,
async: info.async,
mutating: _parseFunctionIsMutating(methodSymbolJson)
);
}

Expand Down Expand Up @@ -142,6 +143,13 @@ ParsedFunctionInfo parseFunctionInfo(
);
}

bool _parseFunctionIsMutating(Json methodSymbolJson) {
nikeokoronkwo marked this conversation as resolved.
Show resolved Hide resolved
return methodSymbolJson['declarationFragments']
.where((j) => j['kind'].get<String?>() == 'keyword'
&& j['spelling'].get<String?>() == 'mutating')
.isNotEmpty;
}

ReferredType _parseFunctionReturnType(
Json methodSymbolJson,
ParsedSymbolgraph symbolgraph,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public struct MyStruct {
public func myMethod3() {
1 + 1
}

public mutating func myMethod4() {
2 + 2
}
}

public struct MyOtherStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ import Foundation
return wrappedInstance.myMethod3()
}

@objc public func myMethod4() {
return wrappedInstance.myMethod4()
}

}

Loading