Skip to content

Commit c53db71

Browse files
committed
[pigeon]fix casting failure due to nested optional
1 parent 7dd9980 commit c53db71

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

packages/pigeon/lib/swift_generator.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ import FlutterMacOS
169169
Set<String> customEnumNames,
170170
) {
171171
final String className = klass.name;
172-
indent.write('static func fromList(_ list: [Any]) -> $className? ');
172+
indent.write('static func fromList(_ list: [Any?]) -> $className? ');
173173

174174
indent.addScoped('{', '}', () {
175175
enumerate(getFieldsInSerializationOrder(klass),
@@ -524,7 +524,7 @@ import FlutterMacOS
524524
indent.writeln('case ${customClass.enumeration}:');
525525
indent.nest(1, () {
526526
indent.writeln(
527-
'return ${customClass.name}.fromList(self.readValue() as! [Any])');
527+
'return ${customClass.name}.fromList(self.readValue() as! [Any?])');
528528
});
529529
}
530530
indent.writeln('default:');
@@ -628,7 +628,7 @@ import FlutterMacOS
628628
if (listEncodedClassNames != null &&
629629
listEncodedClassNames.contains(type.baseName)) {
630630
indent.writeln('var $variableName: $fieldType? = nil');
631-
indent.write('if let ${variableName}List = $value as! [Any]? ');
631+
indent.write('if let ${variableName}List = $value as! [Any?]? ');
632632
indent.addScoped('{', '}', () {
633633
indent.writeln(
634634
'$variableName = $fieldType.fromList(${variableName}List)');
@@ -652,7 +652,7 @@ import FlutterMacOS
652652
if (listEncodedClassNames != null &&
653653
listEncodedClassNames.contains(type.baseName)) {
654654
indent.writeln(
655-
'let $variableName = $fieldType.fromList($value as! [Any])!');
655+
'let $variableName = $fieldType.fromList($value as! [Any?])!');
656656
} else {
657657
indent.writeln(
658658
'let $variableName = ${castForceUnwrap(value, type, root)}');
@@ -695,7 +695,7 @@ import FlutterMacOS
695695
696696
private func nilOrValue<T>(_ value: Any?) -> T? {
697697
if value is NSNull { return nil }
698-
return (value as Any) as! T?
698+
return value as! T?
699699
}''');
700700
}
701701

packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private func wrapError(_ error: Any) -> [Any?] {
3535

3636
private func nilOrValue<T>(_ value: Any?) -> T? {
3737
if value is NSNull { return nil }
38-
return (value as Any) as! T?
38+
return value as! T?
3939
}
4040

4141
enum AnEnum: Int {
@@ -59,7 +59,7 @@ struct AllTypes {
5959
var anEnum: AnEnum
6060
var aString: String
6161

62-
static func fromList(_ list: [Any]) -> AllTypes? {
62+
static func fromList(_ list: [Any?]) -> AllTypes? {
6363
let aBool = list[0] as! Bool
6464
let anInt = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32)
6565
let anInt64 = list[2] is Int64 ? list[2] as! Int64 : Int64(list[2] as! Int32)
@@ -124,7 +124,7 @@ struct AllNullableTypes {
124124
var aNullableEnum: AnEnum? = nil
125125
var aNullableString: String? = nil
126126

127-
static func fromList(_ list: [Any]) -> AllNullableTypes? {
127+
static func fromList(_ list: [Any?]) -> AllNullableTypes? {
128128
let aNullableBool: Bool? = nilOrValue(list[0])
129129
let aNullableInt: Int64? = list[1] is NSNull ? nil : (list[1] is Int64? ? list[1] as! Int64? : Int64(list[1] as! Int32))
130130
let aNullableInt64: Int64? = list[2] is NSNull ? nil : (list[2] is Int64? ? list[2] as! Int64? : Int64(list[2] as! Int32))
@@ -188,8 +188,8 @@ struct AllNullableTypes {
188188
struct AllNullableTypesWrapper {
189189
var values: AllNullableTypes
190190

191-
static func fromList(_ list: [Any]) -> AllNullableTypesWrapper? {
192-
let values = AllNullableTypes.fromList(list[0] as! [Any])!
191+
static func fromList(_ list: [Any?]) -> AllNullableTypesWrapper? {
192+
let values = AllNullableTypes.fromList(list[0] as! [Any?])!
193193

194194
return AllNullableTypesWrapper(
195195
values: values
@@ -208,7 +208,7 @@ struct AllNullableTypesWrapper {
208208
struct TestMessage {
209209
var testList: [Any]? = nil
210210

211-
static func fromList(_ list: [Any]) -> TestMessage? {
211+
static func fromList(_ list: [Any?]) -> TestMessage? {
212212
let testList: [Any]? = nilOrValue(list[0])
213213

214214
return TestMessage(
@@ -226,13 +226,13 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader {
226226
override func readValue(ofType type: UInt8) -> Any? {
227227
switch type {
228228
case 128:
229-
return AllNullableTypes.fromList(self.readValue() as! [Any])
229+
return AllNullableTypes.fromList(self.readValue() as! [Any?])
230230
case 129:
231-
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any])
231+
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?])
232232
case 130:
233-
return AllTypes.fromList(self.readValue() as! [Any])
233+
return AllTypes.fromList(self.readValue() as! [Any?])
234234
case 131:
235-
return TestMessage.fromList(self.readValue() as! [Any])
235+
return TestMessage.fromList(self.readValue() as! [Any?])
236236
default:
237237
return super.readValue(ofType: type)
238238
}
@@ -1514,13 +1514,13 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader {
15141514
override func readValue(ofType type: UInt8) -> Any? {
15151515
switch type {
15161516
case 128:
1517-
return AllNullableTypes.fromList(self.readValue() as! [Any])
1517+
return AllNullableTypes.fromList(self.readValue() as! [Any?])
15181518
case 129:
1519-
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any])
1519+
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?])
15201520
case 130:
1521-
return AllTypes.fromList(self.readValue() as! [Any])
1521+
return AllTypes.fromList(self.readValue() as! [Any?])
15221522
case 131:
1523-
return TestMessage.fromList(self.readValue() as! [Any])
1523+
return TestMessage.fromList(self.readValue() as! [Any?])
15241524
default:
15251525
return super.readValue(ofType: type)
15261526
}
@@ -1829,7 +1829,7 @@ private class FlutterSmallApiCodecReader: FlutterStandardReader {
18291829
override func readValue(ofType type: UInt8) -> Any? {
18301830
switch type {
18311831
case 128:
1832-
return TestMessage.fromList(self.readValue() as! [Any])
1832+
return TestMessage.fromList(self.readValue() as! [Any?])
18331833
default:
18341834
return super.readValue(ofType: type)
18351835
}

packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private func wrapError(_ error: Any) -> [Any?] {
3535

3636
private func nilOrValue<T>(_ value: Any?) -> T? {
3737
if value is NSNull { return nil }
38-
return (value as Any) as! T?
38+
return value as! T?
3939
}
4040

4141
enum AnEnum: Int {
@@ -59,7 +59,7 @@ struct AllTypes {
5959
var anEnum: AnEnum
6060
var aString: String
6161

62-
static func fromList(_ list: [Any]) -> AllTypes? {
62+
static func fromList(_ list: [Any?]) -> AllTypes? {
6363
let aBool = list[0] as! Bool
6464
let anInt = list[1] is Int64 ? list[1] as! Int64 : Int64(list[1] as! Int32)
6565
let anInt64 = list[2] is Int64 ? list[2] as! Int64 : Int64(list[2] as! Int32)
@@ -124,7 +124,7 @@ struct AllNullableTypes {
124124
var aNullableEnum: AnEnum? = nil
125125
var aNullableString: String? = nil
126126

127-
static func fromList(_ list: [Any]) -> AllNullableTypes? {
127+
static func fromList(_ list: [Any?]) -> AllNullableTypes? {
128128
let aNullableBool: Bool? = nilOrValue(list[0])
129129
let aNullableInt: Int64? = list[1] is NSNull ? nil : (list[1] is Int64? ? list[1] as! Int64? : Int64(list[1] as! Int32))
130130
let aNullableInt64: Int64? = list[2] is NSNull ? nil : (list[2] is Int64? ? list[2] as! Int64? : Int64(list[2] as! Int32))
@@ -188,8 +188,8 @@ struct AllNullableTypes {
188188
struct AllNullableTypesWrapper {
189189
var values: AllNullableTypes
190190

191-
static func fromList(_ list: [Any]) -> AllNullableTypesWrapper? {
192-
let values = AllNullableTypes.fromList(list[0] as! [Any])!
191+
static func fromList(_ list: [Any?]) -> AllNullableTypesWrapper? {
192+
let values = AllNullableTypes.fromList(list[0] as! [Any?])!
193193

194194
return AllNullableTypesWrapper(
195195
values: values
@@ -208,7 +208,7 @@ struct AllNullableTypesWrapper {
208208
struct TestMessage {
209209
var testList: [Any]? = nil
210210

211-
static func fromList(_ list: [Any]) -> TestMessage? {
211+
static func fromList(_ list: [Any?]) -> TestMessage? {
212212
let testList: [Any]? = nilOrValue(list[0])
213213

214214
return TestMessage(
@@ -226,13 +226,13 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader {
226226
override func readValue(ofType type: UInt8) -> Any? {
227227
switch type {
228228
case 128:
229-
return AllNullableTypes.fromList(self.readValue() as! [Any])
229+
return AllNullableTypes.fromList(self.readValue() as! [Any?])
230230
case 129:
231-
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any])
231+
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?])
232232
case 130:
233-
return AllTypes.fromList(self.readValue() as! [Any])
233+
return AllTypes.fromList(self.readValue() as! [Any?])
234234
case 131:
235-
return TestMessage.fromList(self.readValue() as! [Any])
235+
return TestMessage.fromList(self.readValue() as! [Any?])
236236
default:
237237
return super.readValue(ofType: type)
238238
}
@@ -1514,13 +1514,13 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader {
15141514
override func readValue(ofType type: UInt8) -> Any? {
15151515
switch type {
15161516
case 128:
1517-
return AllNullableTypes.fromList(self.readValue() as! [Any])
1517+
return AllNullableTypes.fromList(self.readValue() as! [Any?])
15181518
case 129:
1519-
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any])
1519+
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?])
15201520
case 130:
1521-
return AllTypes.fromList(self.readValue() as! [Any])
1521+
return AllTypes.fromList(self.readValue() as! [Any?])
15221522
case 131:
1523-
return TestMessage.fromList(self.readValue() as! [Any])
1523+
return TestMessage.fromList(self.readValue() as! [Any?])
15241524
default:
15251525
return super.readValue(ofType: type)
15261526
}
@@ -1829,7 +1829,7 @@ private class FlutterSmallApiCodecReader: FlutterStandardReader {
18291829
override func readValue(ofType type: UInt8) -> Any? {
18301830
switch type {
18311831
case 128:
1832-
return TestMessage.fromList(self.readValue() as! [Any])
1832+
return TestMessage.fromList(self.readValue() as! [Any?])
18331833
default:
18341834
return super.readValue(ofType: type)
18351835
}

0 commit comments

Comments
 (0)