Skip to content

Commit e20c1b7

Browse files
authored
[pigeon] removes safe casting from nullables in kotlin and swift (flutter#3284)
[pigeon] removes safe casting from nullables in kotlin and swift
1 parent f39c97d commit e20c1b7

File tree

28 files changed

+117
-112
lines changed

28 files changed

+117
-112
lines changed

packages/pigeon/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 9.0.2
2+
3+
* [swift] Removes safe casting from decode process.
4+
* [kotlin] Removes safe casting from decode process.
5+
16
## 9.0.1
27

38
* Updates links for the merge of flutter/plugins into flutter/packages.

packages/pigeon/lib/generator_tools.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'ast.dart';
1111
/// The current version of pigeon.
1212
///
1313
/// This must match the version in pubspec.yaml.
14-
const String pigeonVersion = '9.0.1';
14+
const String pigeonVersion = '9.0.2';
1515

1616
/// Read all the content from [stdin] to a String.
1717
String readStdin() {

packages/pigeon/lib/kotlin_generator.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,23 +228,23 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
228228
if (!hostDatatype.isBuiltin &&
229229
customClassNames.contains(field.type.baseName)) {
230230
indent.write('val ${field.name}: $fieldType? = ');
231-
indent.add('($listValue as? List<Any?>)?.let ');
231+
indent.add('($listValue as List<Any?>?)?.let ');
232232
indent.addScoped('{', '}', () {
233233
indent.writeln('$fieldType.fromList(it)');
234234
});
235235
} else if (!hostDatatype.isBuiltin &&
236236
customEnumNames.contains(field.type.baseName)) {
237237
indent.write('val ${field.name}: $fieldType? = ');
238-
indent.add('($listValue as? Int)?.let ');
238+
indent.add('($listValue as Int?)?.let ');
239239
indent.addScoped('{', '}', () {
240240
indent.writeln('$fieldType.ofRaw(it)');
241241
});
242242
} else if (isInt) {
243243
indent.write('val ${field.name} = $listValue');
244244
indent.addln(
245-
'.let { if (it is Int) it.toLong() else it as? Long }');
245+
'.let { if (it is Int) it.toLong() else it as Long? }');
246246
} else {
247-
indent.writeln('val ${field.name} = $listValue as? $fieldType');
247+
indent.writeln('val ${field.name} = $listValue as $fieldType?');
248248
}
249249
} else {
250250
if (!hostDatatype.isBuiltin &&

packages/pigeon/lib/swift_generator.dart

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

176176
indent.addScoped('{', '}', () {
177177
enumerate(getFieldsInSerializationOrder(klass),
@@ -185,27 +185,27 @@ import FlutterMacOS
185185
if (!hostDatatype.isBuiltin &&
186186
customClassNames.contains(field.type.baseName)) {
187187
indent.writeln('var ${field.name}: $fieldType? = nil');
188-
indent.write('if let ${field.name}List = $listValue as? [Any?] ');
188+
indent.write('if let ${field.name}List = $listValue as! [Any]? ');
189189
indent.addScoped('{', '}', () {
190190
indent.writeln(
191-
'${field.name} = $fieldType.fromList(${field.name}List)');
191+
'${field.name} = $fieldType.fromList(${field.name}List as [Any])');
192192
});
193193
} else if (!hostDatatype.isBuiltin &&
194194
customEnumNames.contains(field.type.baseName)) {
195195
indent.writeln('var ${field.name}: $fieldType? = nil');
196-
indent.write('if let ${field.name}RawValue = $listValue as? Int ');
196+
indent.write('if let ${field.name}RawValue = $listValue as! Int? ');
197197
indent.addScoped('{', '}', () {
198198
indent.writeln(
199199
'${field.name} = $fieldType(rawValue: ${field.name}RawValue)');
200200
});
201201
} else {
202-
indent.writeln('let ${field.name} = $listValue as? $fieldType ');
202+
indent.writeln('let ${field.name} = $listValue as! $fieldType? ');
203203
}
204204
} else {
205205
if (!hostDatatype.isBuiltin &&
206206
customClassNames.contains(field.type.baseName)) {
207207
indent.writeln(
208-
'let ${field.name} = $fieldType.fromList($listValue as! [Any?])!');
208+
'let ${field.name} = $fieldType.fromList($listValue as! [Any])!');
209209
} else if (!hostDatatype.isBuiltin &&
210210
customEnumNames.contains(field.type.baseName)) {
211211
indent.writeln(
@@ -691,9 +691,9 @@ String _flattenTypeArguments(List<TypeDeclaration> args) {
691691
String _swiftTypeForBuiltinGenericDartType(TypeDeclaration type) {
692692
if (type.typeArguments.isEmpty) {
693693
if (type.baseName == 'List') {
694-
return '[Any?]';
694+
return '[Any]';
695695
} else if (type.baseName == 'Map') {
696-
return '[AnyHashable: Any?]';
696+
return '[AnyHashable: Any]';
697697
} else {
698698
return 'Any';
699699
}

packages/pigeon/mock_handler_tester/test/message.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.0.1), do not edit directly.
5+
// Autogenerated from Pigeon (v9.0.2), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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
88

packages/pigeon/mock_handler_tester/test/test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.0.1), do not edit directly.
5+
// Autogenerated from Pigeon (v9.0.2), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import
88
// ignore_for_file: avoid_relative_lib_imports

packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.0.1), do not edit directly.
5+
// Autogenerated from Pigeon (v9.0.2), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
package com.example.alternate_language_test_plugin;

packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.0.1), do not edit directly.
5+
// Autogenerated from Pigeon (v9.0.2), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
#import <Foundation/Foundation.h>

packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.0.1), do not edit directly.
5+
// Autogenerated from Pigeon (v9.0.2), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
#import "CoreTests.gen.h"

packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.0.1), do not edit directly.
5+
// Autogenerated from Pigeon (v9.0.2), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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
88

0 commit comments

Comments
 (0)