From 1ecebead54529ae9bfe7cf7e43193d0c4b23ac37 Mon Sep 17 00:00:00 2001 From: Tarrin Neal Date: Tue, 28 Feb 2023 07:54:49 -0800 Subject: [PATCH] [pigeon] removes safe casting from nullables in kotlin and swift (#3284) [pigeon] removes safe casting from nullables in kotlin and swift --- packages/pigeon/CHANGELOG.md | 5 ++ packages/pigeon/lib/generator_tools.dart | 2 +- packages/pigeon/lib/kotlin_generator.dart | 8 +-- packages/pigeon/lib/swift_generator.dart | 16 +++--- .../mock_handler_tester/test/message.dart | 2 +- .../pigeon/mock_handler_tester/test/test.dart | 2 +- .../CoreTests.java | 2 +- .../ios/Classes/CoreTests.gen.h | 2 +- .../ios/Classes/CoreTests.gen.m | 2 +- .../lib/core_tests.gen.dart | 2 +- .../lib/flutter_unittests.gen.dart | 2 +- .../lib/multiple_arity.gen.dart | 2 +- .../lib/non_null_fields.gen.dart | 2 +- .../lib/null_fields.gen.dart | 2 +- .../lib/nullable_returns.gen.dart | 2 +- .../lib/primitive.gen.dart | 2 +- .../lib/src/generated/core_tests.gen.dart | 2 +- .../com/example/test_plugin/CoreTests.gen.kt | 32 +++++------ .../ios/RunnerTests/AllDatatypesTests.swift | 2 +- .../ios/RunnerTests/PrimitiveTests.swift | 4 +- .../ios/Classes/CoreTests.gen.swift | 56 +++++++++---------- .../test_plugin/ios/Classes/TestPlugin.swift | 2 +- .../macos/Classes/CoreTests.gen.swift | 56 +++++++++---------- .../windows/pigeon/core_tests.gen.cpp | 2 +- .../windows/pigeon/core_tests.gen.h | 2 +- packages/pigeon/pubspec.yaml | 2 +- .../pigeon/test/kotlin_generator_test.dart | 4 +- .../pigeon/test/swift_generator_test.dart | 10 ++-- 28 files changed, 117 insertions(+), 112 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 140d5076262d..dc35906630f2 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,8 @@ +## 9.0.2 + +* [swift] Removes safe casting from decode process. +* [kotlin] Removes safe casting from decode process. + ## 9.0.1 * Updates links for the merge of flutter/plugins into flutter/packages. diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 7065903cb5b0..b7f3b24fc754 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -11,7 +11,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '9.0.1'; +const String pigeonVersion = '9.0.2'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/lib/kotlin_generator.dart b/packages/pigeon/lib/kotlin_generator.dart index 7c45dec6e171..b775b3923cb2 100644 --- a/packages/pigeon/lib/kotlin_generator.dart +++ b/packages/pigeon/lib/kotlin_generator.dart @@ -228,23 +228,23 @@ class KotlinGenerator extends StructuredGenerator { if (!hostDatatype.isBuiltin && customClassNames.contains(field.type.baseName)) { indent.write('val ${field.name}: $fieldType? = '); - indent.add('($listValue as? List)?.let '); + indent.add('($listValue as List?)?.let '); indent.addScoped('{', '}', () { indent.writeln('$fieldType.fromList(it)'); }); } else if (!hostDatatype.isBuiltin && customEnumNames.contains(field.type.baseName)) { indent.write('val ${field.name}: $fieldType? = '); - indent.add('($listValue as? Int)?.let '); + indent.add('($listValue as Int?)?.let '); indent.addScoped('{', '}', () { indent.writeln('$fieldType.ofRaw(it)'); }); } else if (isInt) { indent.write('val ${field.name} = $listValue'); indent.addln( - '.let { if (it is Int) it.toLong() else it as? Long }'); + '.let { if (it is Int) it.toLong() else it as Long? }'); } else { - indent.writeln('val ${field.name} = $listValue as? $fieldType'); + indent.writeln('val ${field.name} = $listValue as $fieldType?'); } } else { if (!hostDatatype.isBuiltin && diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 0d7a9e8e68a5..2ba822b97518 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -171,7 +171,7 @@ import FlutterMacOS Set 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), @@ -185,27 +185,27 @@ import FlutterMacOS if (!hostDatatype.isBuiltin && customClassNames.contains(field.type.baseName)) { indent.writeln('var ${field.name}: $fieldType? = nil'); - indent.write('if let ${field.name}List = $listValue as? [Any?] '); + indent.write('if let ${field.name}List = $listValue as! [Any]? '); indent.addScoped('{', '}', () { indent.writeln( - '${field.name} = $fieldType.fromList(${field.name}List)'); + '${field.name} = $fieldType.fromList(${field.name}List as [Any])'); }); } else if (!hostDatatype.isBuiltin && customEnumNames.contains(field.type.baseName)) { indent.writeln('var ${field.name}: $fieldType? = nil'); - indent.write('if let ${field.name}RawValue = $listValue as? Int '); + indent.write('if let ${field.name}RawValue = $listValue as! Int? '); indent.addScoped('{', '}', () { indent.writeln( '${field.name} = $fieldType(rawValue: ${field.name}RawValue)'); }); } else { - indent.writeln('let ${field.name} = $listValue as? $fieldType '); + indent.writeln('let ${field.name} = $listValue as! $fieldType? '); } } else { if (!hostDatatype.isBuiltin && customClassNames.contains(field.type.baseName)) { indent.writeln( - 'let ${field.name} = $fieldType.fromList($listValue as! [Any?])!'); + 'let ${field.name} = $fieldType.fromList($listValue as! [Any])!'); } else if (!hostDatatype.isBuiltin && customEnumNames.contains(field.type.baseName)) { indent.writeln( @@ -691,9 +691,9 @@ String _flattenTypeArguments(List args) { String _swiftTypeForBuiltinGenericDartType(TypeDeclaration type) { if (type.typeArguments.isEmpty) { if (type.baseName == 'List') { - return '[Any?]'; + return '[Any]'; } else if (type.baseName == 'Map') { - return '[AnyHashable: Any?]'; + return '[AnyHashable: Any]'; } else { return 'Any'; } diff --git a/packages/pigeon/mock_handler_tester/test/message.dart b/packages/pigeon/mock_handler_tester/test/message.dart index a55f0c90c6f2..71699ed7d164 100644 --- a/packages/pigeon/mock_handler_tester/test/message.dart +++ b/packages/pigeon/mock_handler_tester/test/message.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/mock_handler_tester/test/test.dart b/packages/pigeon/mock_handler_tester/test/test.dart index 10a3112bd7fc..88c1c1ee092b 100644 --- a/packages/pigeon/mock_handler_tester/test/test.dart +++ b/packages/pigeon/mock_handler_tester/test/test.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import // ignore_for_file: avoid_relative_lib_imports diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java index aa77a4c7731b..4cf7c13551bf 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.alternate_language_test_plugin; diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h index 1744498a8764..61dc902f2a8b 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #import diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m index 4e752b08ef79..64681f92bd53 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "CoreTests.gen.h" diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart index e8b25be86401..5e38b604c857 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart index 81caf4e4c86b..16d19678aec6 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart index adb653a0b4c0..103dd5b6092f 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/multiple_arity.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart index 0f1524fca074..061ee32a7d9f 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/non_null_fields.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart index 8595fcd31207..7d7f3376fc8a 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/null_fields.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart index 74ffb9c1eda9..8a09cb33c4d0 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/nullable_returns.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart index 50b7567b608b..c6189e3f39f0 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/primitive.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart index e8b25be86401..5e38b604c857 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt index fb328a712a72..032f6dab440b 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.test_plugin @@ -109,22 +109,22 @@ data class AllNullableTypes ( companion object { @Suppress("UNCHECKED_CAST") fun fromList(list: List): AllNullableTypes { - val aNullableBool = list[0] as? Boolean - val aNullableInt = list[1].let { if (it is Int) it.toLong() else it as? Long } - val aNullableDouble = list[2] as? Double - val aNullableByteArray = list[3] as? ByteArray - val aNullable4ByteArray = list[4] as? IntArray - val aNullable8ByteArray = list[5] as? LongArray - val aNullableFloatArray = list[6] as? DoubleArray - val aNullableList = list[7] as? List - val aNullableMap = list[8] as? Map - val nullableNestedList = list[9] as? List?> - val nullableMapWithAnnotations = list[10] as? Map - val nullableMapWithObject = list[11] as? Map - val aNullableEnum: AnEnum? = (list[12] as? Int)?.let { + val aNullableBool = list[0] as Boolean? + val aNullableInt = list[1].let { if (it is Int) it.toLong() else it as Long? } + val aNullableDouble = list[2] as Double? + val aNullableByteArray = list[3] as ByteArray? + val aNullable4ByteArray = list[4] as IntArray? + val aNullable8ByteArray = list[5] as LongArray? + val aNullableFloatArray = list[6] as DoubleArray? + val aNullableList = list[7] as List? + val aNullableMap = list[8] as Map? + val nullableNestedList = list[9] as List?>? + val nullableMapWithAnnotations = list[10] as Map? + val nullableMapWithObject = list[11] as Map? + val aNullableEnum: AnEnum? = (list[12] as Int?)?.let { AnEnum.ofRaw(it) } - val aNullableString = list[13] as? String + val aNullableString = list[13] as String? return AllNullableTypes(aNullableBool, aNullableInt, aNullableDouble, aNullableByteArray, aNullable4ByteArray, aNullable8ByteArray, aNullableFloatArray, aNullableList, aNullableMap, nullableNestedList, nullableMapWithAnnotations, nullableMapWithObject, aNullableEnum, aNullableString) } } @@ -179,7 +179,7 @@ data class TestMessage ( companion object { @Suppress("UNCHECKED_CAST") fun fromList(list: List): TestMessage { - val testList = list[0] as? List + val testList = list[0] as List? return TestMessage(testList) } } diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AllDatatypesTests.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AllDatatypesTests.swift index 08b9b3b15ebb..4992841786e1 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AllDatatypesTests.swift +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AllDatatypesTests.swift @@ -37,7 +37,7 @@ class AllDatatypesTests: XCTestCase { func testAllEquals() throws { let everything = AllNullableTypes( - aNullableBool: false, + aNullableBool: true, aNullableInt: 1, aNullableDouble: 2.0, aNullableByteArray: FlutterStandardTypedData(bytes: "1234".data(using: .utf8)!), diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/PrimitiveTests.swift b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/PrimitiveTests.swift index 2734f3c359e6..861bfa6d4d28 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/PrimitiveTests.swift +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/PrimitiveTests.swift @@ -11,8 +11,8 @@ class MockPrimitiveHostApi: PrimitiveHostApi { func aBool(value: Bool) -> Bool { value } func aString(value: String) -> String { value } func aDouble(value: Double) -> Double { value } - func aMap(value: [AnyHashable: Any?]) -> [AnyHashable: Any?] { value } - func aList(value: [Any?]) -> [Any?] { value } + func aMap(value: [AnyHashable: Any]) -> [AnyHashable: Any] { value } + func aList(value: [Any]) -> [Any] { value } func anInt32List(value: FlutterStandardTypedData) -> FlutterStandardTypedData { value } func aBoolList(value: [Bool?]) -> [Bool?] { value } func aStringIntMap(value: [String?: Int32?]) -> [String?: Int32?] { value } diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index 8b0381f5ed1f..9e1fa4bee614 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -50,12 +50,12 @@ struct AllTypes { var a4ByteArray: FlutterStandardTypedData var a8ByteArray: FlutterStandardTypedData var aFloatArray: FlutterStandardTypedData - var aList: [Any?] - var aMap: [AnyHashable: Any?] + var aList: [Any] + var aMap: [AnyHashable: Any] 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] as! Int32 let aDouble = list[2] as! Double @@ -63,8 +63,8 @@ struct AllTypes { let a4ByteArray = list[4] as! FlutterStandardTypedData let a8ByteArray = list[5] as! FlutterStandardTypedData let aFloatArray = list[6] as! FlutterStandardTypedData - let aList = list[7] as! [Any?] - let aMap = list[8] as! [AnyHashable: Any?] + let aList = list[7] as! [Any] + let aMap = list[8] as! [AnyHashable: Any] let anEnum = AnEnum(rawValue: list[9] as! Int)! let aString = list[10] as! String @@ -108,32 +108,32 @@ struct AllNullableTypes { var aNullable4ByteArray: FlutterStandardTypedData? = nil var aNullable8ByteArray: FlutterStandardTypedData? = nil var aNullableFloatArray: FlutterStandardTypedData? = nil - var aNullableList: [Any?]? = nil - var aNullableMap: [AnyHashable: Any?]? = nil + var aNullableList: [Any]? = nil + var aNullableMap: [AnyHashable: Any]? = nil var nullableNestedList: [[Bool?]?]? = nil var nullableMapWithAnnotations: [String?: String?]? = nil var nullableMapWithObject: [String?: Any?]? = nil var aNullableEnum: AnEnum? = nil var aNullableString: String? = nil - static func fromList(_ list: [Any?]) -> AllNullableTypes? { - let aNullableBool = list[0] as? Bool - let aNullableInt = list[1] as? Int32 - let aNullableDouble = list[2] as? Double - let aNullableByteArray = list[3] as? FlutterStandardTypedData - let aNullable4ByteArray = list[4] as? FlutterStandardTypedData - let aNullable8ByteArray = list[5] as? FlutterStandardTypedData - let aNullableFloatArray = list[6] as? FlutterStandardTypedData - let aNullableList = list[7] as? [Any?] - let aNullableMap = list[8] as? [AnyHashable: Any?] - let nullableNestedList = list[9] as? [[Bool?]?] - let nullableMapWithAnnotations = list[10] as? [String?: String?] - let nullableMapWithObject = list[11] as? [String?: Any?] + static func fromList(_ list: [Any]) -> AllNullableTypes? { + let aNullableBool = list[0] as! Bool? + let aNullableInt = list[1] as! Int32? + let aNullableDouble = list[2] as! Double? + let aNullableByteArray = list[3] as! FlutterStandardTypedData? + let aNullable4ByteArray = list[4] as! FlutterStandardTypedData? + let aNullable8ByteArray = list[5] as! FlutterStandardTypedData? + let aNullableFloatArray = list[6] as! FlutterStandardTypedData? + let aNullableList = list[7] as! [Any]? + let aNullableMap = list[8] as! [AnyHashable: Any]? + let nullableNestedList = list[9] as! [[Bool?]?]? + let nullableMapWithAnnotations = list[10] as! [String?: String?]? + let nullableMapWithObject = list[11] as! [String?: Any?]? var aNullableEnum: AnEnum? = nil - if let aNullableEnumRawValue = list[12] as? Int { + if let aNullableEnumRawValue = list[12] as! Int? { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue) } - let aNullableString = list[13] as? String + let aNullableString = list[13] as! String? return AllNullableTypes( aNullableBool: aNullableBool, @@ -176,8 +176,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 @@ -194,10 +194,10 @@ struct AllNullableTypesWrapper { /// /// Generated class from Pigeon that represents data sent in messages. struct TestMessage { - var testList: [Any?]? = nil + var testList: [Any]? = nil - static func fromList(_ list: [Any?]) -> TestMessage? { - let testList = list[0] as? [Any?] + static func fromList(_ list: [Any]) -> TestMessage? { + let testList = list[0] as! [Any]? return TestMessage( testList: testList diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift index 91962e19cbb5..6c718e9e5038 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -326,4 +326,4 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { completion(.success($0)) } } -} \ No newline at end of file +} diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index 8b0381f5ed1f..9e1fa4bee614 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -50,12 +50,12 @@ struct AllTypes { var a4ByteArray: FlutterStandardTypedData var a8ByteArray: FlutterStandardTypedData var aFloatArray: FlutterStandardTypedData - var aList: [Any?] - var aMap: [AnyHashable: Any?] + var aList: [Any] + var aMap: [AnyHashable: Any] 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] as! Int32 let aDouble = list[2] as! Double @@ -63,8 +63,8 @@ struct AllTypes { let a4ByteArray = list[4] as! FlutterStandardTypedData let a8ByteArray = list[5] as! FlutterStandardTypedData let aFloatArray = list[6] as! FlutterStandardTypedData - let aList = list[7] as! [Any?] - let aMap = list[8] as! [AnyHashable: Any?] + let aList = list[7] as! [Any] + let aMap = list[8] as! [AnyHashable: Any] let anEnum = AnEnum(rawValue: list[9] as! Int)! let aString = list[10] as! String @@ -108,32 +108,32 @@ struct AllNullableTypes { var aNullable4ByteArray: FlutterStandardTypedData? = nil var aNullable8ByteArray: FlutterStandardTypedData? = nil var aNullableFloatArray: FlutterStandardTypedData? = nil - var aNullableList: [Any?]? = nil - var aNullableMap: [AnyHashable: Any?]? = nil + var aNullableList: [Any]? = nil + var aNullableMap: [AnyHashable: Any]? = nil var nullableNestedList: [[Bool?]?]? = nil var nullableMapWithAnnotations: [String?: String?]? = nil var nullableMapWithObject: [String?: Any?]? = nil var aNullableEnum: AnEnum? = nil var aNullableString: String? = nil - static func fromList(_ list: [Any?]) -> AllNullableTypes? { - let aNullableBool = list[0] as? Bool - let aNullableInt = list[1] as? Int32 - let aNullableDouble = list[2] as? Double - let aNullableByteArray = list[3] as? FlutterStandardTypedData - let aNullable4ByteArray = list[4] as? FlutterStandardTypedData - let aNullable8ByteArray = list[5] as? FlutterStandardTypedData - let aNullableFloatArray = list[6] as? FlutterStandardTypedData - let aNullableList = list[7] as? [Any?] - let aNullableMap = list[8] as? [AnyHashable: Any?] - let nullableNestedList = list[9] as? [[Bool?]?] - let nullableMapWithAnnotations = list[10] as? [String?: String?] - let nullableMapWithObject = list[11] as? [String?: Any?] + static func fromList(_ list: [Any]) -> AllNullableTypes? { + let aNullableBool = list[0] as! Bool? + let aNullableInt = list[1] as! Int32? + let aNullableDouble = list[2] as! Double? + let aNullableByteArray = list[3] as! FlutterStandardTypedData? + let aNullable4ByteArray = list[4] as! FlutterStandardTypedData? + let aNullable8ByteArray = list[5] as! FlutterStandardTypedData? + let aNullableFloatArray = list[6] as! FlutterStandardTypedData? + let aNullableList = list[7] as! [Any]? + let aNullableMap = list[8] as! [AnyHashable: Any]? + let nullableNestedList = list[9] as! [[Bool?]?]? + let nullableMapWithAnnotations = list[10] as! [String?: String?]? + let nullableMapWithObject = list[11] as! [String?: Any?]? var aNullableEnum: AnEnum? = nil - if let aNullableEnumRawValue = list[12] as? Int { + if let aNullableEnumRawValue = list[12] as! Int? { aNullableEnum = AnEnum(rawValue: aNullableEnumRawValue) } - let aNullableString = list[13] as? String + let aNullableString = list[13] as! String? return AllNullableTypes( aNullableBool: aNullableBool, @@ -176,8 +176,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 @@ -194,10 +194,10 @@ struct AllNullableTypesWrapper { /// /// Generated class from Pigeon that represents data sent in messages. struct TestMessage { - var testList: [Any?]? = nil + var testList: [Any]? = nil - static func fromList(_ list: [Any?]) -> TestMessage? { - let testList = list[0] as? [Any?] + static func fromList(_ list: [Any]) -> TestMessage? { + let testList = list[0] as! [Any]? return TestMessage( testList: testList diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp index 7cfd6d00307e..2ca8f4d43be8 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #undef _HAS_EXCEPTIONS diff --git a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h index 7ded620e918b..42ac51a02e76 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.h @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v9.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.0.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #ifndef PIGEON_CORE_TESTS_GEN_H_ diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index 2d9ff9a78086..70f92c630e21 100644 --- a/packages/pigeon/pubspec.yaml +++ b/packages/pigeon/pubspec.yaml @@ -2,7 +2,7 @@ name: pigeon description: Code generator tool to make communication between Flutter and the host platform type-safe and easier. repository: https://github.com/flutter/packages/tree/main/packages/pigeon issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon -version: 9.0.1 # This must match the version in lib/generator_tools.dart +version: 9.0.2 # This must match the version in lib/generator_tools.dart environment: sdk: ">=2.12.0 <3.0.0" diff --git a/packages/pigeon/test/kotlin_generator_test.dart b/packages/pigeon/test/kotlin_generator_test.dart index 7ec7ae3c41c7..2aae1029ea66 100644 --- a/packages/pigeon/test/kotlin_generator_test.dart +++ b/packages/pigeon/test/kotlin_generator_test.dart @@ -348,7 +348,7 @@ void main() { expect( code, contains( - 'val aNullableInt = list[9].let { if (it is Int) it.toLong() else it as? Long }')); + 'val aNullableInt = list[9].let { if (it is Int) it.toLong() else it as Long? }')); }); test('gen one flutter api', () { @@ -617,7 +617,7 @@ void main() { expect(code, contains('val nested: Nested? = null')); expect(code, contains('fun fromList(list: List): Outer')); expect( - code, contains('val nested: Nested? = (list[0] as? List)?.let')); + code, contains('val nested: Nested? = (list[0] as List?)?.let')); expect(code, contains('Nested.fromList(it)')); expect(code, contains('fun toList(): List')); }); diff --git a/packages/pigeon/test/swift_generator_test.dart b/packages/pigeon/test/swift_generator_test.dart index e4b1b4cd4bb1..04d6016029a5 100644 --- a/packages/pigeon/test/swift_generator_test.dart +++ b/packages/pigeon/test/swift_generator_test.dart @@ -31,7 +31,7 @@ void main() { final String code = sink.toString(); expect(code, contains('struct Foobar')); expect(code, contains('var field1: Int32? = nil')); - expect(code, contains('static func fromList(_ list: [Any?]) -> Foobar?')); + expect(code, contains('static func fromList(_ list: [Any]) -> Foobar?')); expect(code, contains('func toList() -> [Any?]')); }); @@ -392,7 +392,7 @@ void main() { generator.generate(swiftOptions, root, sink); final String code = sink.toString(); expect(code, contains('struct Foobar')); - expect(code, contains('var field1: [Any?]? = nil')); + expect(code, contains('var field1: [Any]? = nil')); }); test('gen map', () { @@ -412,7 +412,7 @@ void main() { generator.generate(swiftOptions, root, sink); final String code = sink.toString(); expect(code, contains('struct Foobar')); - expect(code, contains('var field1: [AnyHashable: Any?]? = nil')); + expect(code, contains('var field1: [AnyHashable: Any]? = nil')); }); test('gen nested', () { @@ -451,8 +451,8 @@ void main() { expect(code, contains('struct Outer')); expect(code, contains('struct Nested')); expect(code, contains('var nested: Nested? = nil')); - expect(code, contains('static func fromList(_ list: [Any?]) -> Outer?')); - expect(code, contains('nested = Nested.fromList(nestedList)')); + expect(code, contains('static func fromList(_ list: [Any]) -> Outer?')); + expect(code, contains('nested = Nested.fromList(nestedList as [Any])')); expect(code, contains('func toList() -> [Any?]')); });