Skip to content
Merged
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
Next Next commit
[pigeon]fix casting failure due to nested optional
  • Loading branch information
hellohuanlin committed May 2, 2023
commit 041219a81f515b7646b72dcb3b448a779ca74daf
10 changes: 5 additions & 5 deletions packages/pigeon/lib/swift_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ import FlutterMacOS
Set<String> customEnumNames,
) {
final String className = klass.name;
indent.write('static func fromList(_ list: [Any]) -> $className? ');
indent.write('static func fromList(_ list: [Any?]) -> $className? ');

indent.addScoped('{', '}', () {
enumerate(getFieldsInSerializationOrder(klass),
Expand Down Expand Up @@ -524,7 +524,7 @@ import FlutterMacOS
indent.writeln('case ${customClass.enumeration}:');
indent.nest(1, () {
indent.writeln(
'return ${customClass.name}.fromList(self.readValue() as! [Any])');
'return ${customClass.name}.fromList(self.readValue() as! [Any?])');
});
}
indent.writeln('default:');
Expand Down Expand Up @@ -628,7 +628,7 @@ import FlutterMacOS
if (listEncodedClassNames != null &&
listEncodedClassNames.contains(type.baseName)) {
indent.writeln('var $variableName: $fieldType? = nil');
indent.write('if let ${variableName}List = $value as! [Any]? ');
indent.write('if let ${variableName}List = $value as! [Any?]? ');
indent.addScoped('{', '}', () {
indent.writeln(
'$variableName = $fieldType.fromList(${variableName}List)');
Expand All @@ -652,7 +652,7 @@ import FlutterMacOS
if (listEncodedClassNames != null &&
listEncodedClassNames.contains(type.baseName)) {
indent.writeln(
'let $variableName = $fieldType.fromList($value as! [Any])!');
'let $variableName = $fieldType.fromList($value as! [Any?])!');
} else {
indent.writeln(
'let $variableName = ${castForceUnwrap(value, type, root)}');
Expand Down Expand Up @@ -695,7 +695,7 @@ import FlutterMacOS

private func nilOrValue<T>(_ value: Any?) -> T? {
if value is NSNull { return nil }
return (value as Any) as! T?
return value as! T?
}''');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private func wrapError(_ error: Any) -> [Any?] {

private func nilOrValue<T>(_ value: Any?) -> T? {
if value is NSNull { return nil }
return (value as Any) as! T?
return value as! T?
}

enum AnEnum: Int {
Expand All @@ -59,7 +59,7 @@ struct AllTypes {
var anEnum: AnEnum
var aString: String

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

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

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

return AllNullableTypesWrapper(
values: values
Expand All @@ -208,7 +208,7 @@ struct AllNullableTypesWrapper {
struct TestMessage {
var testList: [Any]? = nil

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

return TestMessage(
Expand All @@ -226,13 +226,13 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader {
override func readValue(ofType type: UInt8) -> Any? {
switch type {
case 128:
return AllNullableTypes.fromList(self.readValue() as! [Any])
return AllNullableTypes.fromList(self.readValue() as! [Any?])
case 129:
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any])
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?])
case 130:
return AllTypes.fromList(self.readValue() as! [Any])
return AllTypes.fromList(self.readValue() as! [Any?])
case 131:
return TestMessage.fromList(self.readValue() as! [Any])
return TestMessage.fromList(self.readValue() as! [Any?])
default:
return super.readValue(ofType: type)
}
Expand Down Expand Up @@ -1514,13 +1514,13 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader {
override func readValue(ofType type: UInt8) -> Any? {
switch type {
case 128:
return AllNullableTypes.fromList(self.readValue() as! [Any])
return AllNullableTypes.fromList(self.readValue() as! [Any?])
case 129:
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any])
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?])
case 130:
return AllTypes.fromList(self.readValue() as! [Any])
return AllTypes.fromList(self.readValue() as! [Any?])
case 131:
return TestMessage.fromList(self.readValue() as! [Any])
return TestMessage.fromList(self.readValue() as! [Any?])
default:
return super.readValue(ofType: type)
}
Expand Down Expand Up @@ -1829,7 +1829,7 @@ private class FlutterSmallApiCodecReader: FlutterStandardReader {
override func readValue(ofType type: UInt8) -> Any? {
switch type {
case 128:
return TestMessage.fromList(self.readValue() as! [Any])
return TestMessage.fromList(self.readValue() as! [Any?])
default:
return super.readValue(ofType: type)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private func wrapError(_ error: Any) -> [Any?] {

private func nilOrValue<T>(_ value: Any?) -> T? {
if value is NSNull { return nil }
return (value as Any) as! T?
return value as! T?
}

enum AnEnum: Int {
Expand All @@ -59,7 +59,7 @@ struct AllTypes {
var anEnum: AnEnum
var aString: String

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

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

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

return AllNullableTypesWrapper(
values: values
Expand All @@ -208,7 +208,7 @@ struct AllNullableTypesWrapper {
struct TestMessage {
var testList: [Any]? = nil

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

return TestMessage(
Expand All @@ -226,13 +226,13 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader {
override func readValue(ofType type: UInt8) -> Any? {
switch type {
case 128:
return AllNullableTypes.fromList(self.readValue() as! [Any])
return AllNullableTypes.fromList(self.readValue() as! [Any?])
case 129:
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any])
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?])
case 130:
return AllTypes.fromList(self.readValue() as! [Any])
return AllTypes.fromList(self.readValue() as! [Any?])
case 131:
return TestMessage.fromList(self.readValue() as! [Any])
return TestMessage.fromList(self.readValue() as! [Any?])
default:
return super.readValue(ofType: type)
}
Expand Down Expand Up @@ -1514,13 +1514,13 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader {
override func readValue(ofType type: UInt8) -> Any? {
switch type {
case 128:
return AllNullableTypes.fromList(self.readValue() as! [Any])
return AllNullableTypes.fromList(self.readValue() as! [Any?])
case 129:
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any])
return AllNullableTypesWrapper.fromList(self.readValue() as! [Any?])
case 130:
return AllTypes.fromList(self.readValue() as! [Any])
return AllTypes.fromList(self.readValue() as! [Any?])
case 131:
return TestMessage.fromList(self.readValue() as! [Any])
return TestMessage.fromList(self.readValue() as! [Any?])
default:
return super.readValue(ofType: type)
}
Expand Down Expand Up @@ -1829,7 +1829,7 @@ private class FlutterSmallApiCodecReader: FlutterStandardReader {
override func readValue(ofType type: UInt8) -> Any? {
switch type {
case 128:
return TestMessage.fromList(self.readValue() as! [Any])
return TestMessage.fromList(self.readValue() as! [Any?])
default:
return super.readValue(ofType: type)
}
Expand Down