Skip to content

Commit 9b8d79b

Browse files
authored
Support globals with explicit getters/setters (#1733)
1 parent b2aca7e commit 9b8d79b

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_variable_declaration.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ GlobalVariableDeclaration parseGlobalVariableDeclaration(
2929
ParsedSymbolgraph symbolgraph, {
3030
bool isStatic = false,
3131
}) {
32+
final isConstant = _parseVariableIsConstant(variableSymbolJson);
33+
final hasSetter = _parsePropertyHasSetter(variableSymbolJson);
3234
return GlobalVariableDeclaration(
3335
id: parseSymbolId(variableSymbolJson),
3436
name: parseSymbolName(variableSymbolJson),
3537
type: _parseVariableType(variableSymbolJson, symbolgraph),
36-
isConstant: _parseVariableIsConstant(variableSymbolJson),
38+
isConstant: isConstant || !hasSetter,
3739
);
3840
}
3941

pkgs/swift2objc/test/integration/global_variables_and_functions_input.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ public let globalRepresentableConstant = 1
66
public var globalCustomVariable = MyOtherClass()
77
public let globalCustomConstant = MyOtherClass()
88

9+
public var globalGetterVariable: Double { get { 123 } }
10+
public var globalSetterVariable: Double { get { 123 } set {} }
11+
912
public func globalCustomFunction(label1 param1: Int, param2: MyOtherClass) -> MyOtherClass {
1013
return MyOtherClass()
1114
}

pkgs/swift2objc/test/integration/global_variables_and_functions_output.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ import Foundation
1818
}
1919
}
2020

21+
@objc static public var globalGetterVariableWrapper: Double {
22+
get {
23+
globalGetterVariable
24+
}
25+
}
26+
27+
@objc static public var globalSetterVariableWrapper: Double {
28+
get {
29+
globalSetterVariable
30+
}
31+
set {
32+
globalSetterVariable = newValue
33+
}
34+
}
35+
2136
@objc static public var globalRepresentableConstantWrapper: Int {
2237
get {
2338
globalRepresentableConstant

0 commit comments

Comments
 (0)