Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
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
5 changes: 5 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 9.0.6

* [kotlin] Removes safe casting from decode process.
* [swift] Removes safe casting from decode process.

## 9.0.5

* Removes the unnecessary Flutter constraint.
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.5';
const String pigeonVersion = '9.0.6';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
46 changes: 23 additions & 23 deletions packages/pigeon/lib/kotlin_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,10 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
});
} else if (isInt) {
indent.write('val ${field.name} = $listValue');
indent.addln(
'.let { if (it is Int) it.toLong() else it as Long? }');
indent.addln('.let { ${_cast(listValue, type: field.type)} }');
} else {
indent.writeln(
'val ${field.name} = ${_cast(listValue, kotlinType: '$fieldType?')}');
'val ${field.name} = ${_cast(listValue, type: field.type)}');
}
} else {
if (!hostDatatype.isBuiltin &&
Expand All @@ -259,11 +258,10 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
'val ${field.name} = $fieldType.ofRaw($listValue as Int)!!');
} else if (isInt) {
indent.write('val ${field.name} = $listValue');
indent
.addln('.let { if (it is Int) it.toLong() else it as Long }');
indent.addln('.let { ${_cast(listValue, type: field.type)} }');
} else {
indent.writeln(
'val ${field.name} = ${_cast(listValue, kotlinType: fieldType)}');
'val ${field.name} = ${_cast(listValue, type: field.type)}');
}
}
});
Expand Down Expand Up @@ -384,15 +382,8 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
});
} else {
indent.addScoped('{', '}', () {
if (func.returnType.baseName == 'int') {
final String forceUnwrap =
func.returnType.isNullable ? '?' : '';
indent.writeln(
'val result = if (it is Int) it.toLong() else it as$forceUnwrap Long');
} else {
indent.writeln(
'val result = ${_cast('it', kotlinType: returnType, safeCast: func.returnType.isNullable)}');
}
indent.writeln(
'val result = ${_cast('it', type: func.returnType)}');
indent.writeln('callback(result)');
});
}
Expand Down Expand Up @@ -678,11 +669,9 @@ String _castForceUnwrap(String value, TypeDeclaration type, Root root) {
// a Dart 'int'. To keep things simple we just use 64bit
// longs in Pigeon with Kotlin.
if (type.baseName == 'int') {
final String castUnwrap = type.isNullable ? '?' : '';
return '$value.let { if (it is Int) it.toLong() else it as$castUnwrap Long }';
return '$value.let { ${_cast(value, type: type)} }';
} else {
return _cast(value,
kotlinType: _kotlinTypeForDartType(type), safeCast: type.isNullable);
return _cast(value, type: type);
}
}
}
Expand Down Expand Up @@ -748,11 +737,22 @@ String _nullsafeKotlinTypeForDartType(TypeDeclaration type) {
}

/// Returns an expression to cast [variable] to [kotlinType].
String _cast(String variable,
{required String kotlinType, bool safeCast = false}) {
String _cast(String variable, {required TypeDeclaration type}) {
// Special-case Any, since no-op casts cause warnings.
if (kotlinType == 'Any?' || (safeCast && kotlinType == 'Any')) {
final String typeString = _kotlinTypeForDartType(type);
if (typeString == 'Any?' || (type.isNullable && typeString == 'Any')) {
return variable;
}
return '$variable as${safeCast ? '?' : ''} $kotlinType';
if (typeString == 'Int' ||
typeString == 'Int?' ||
typeString == 'Long' ||
typeString == 'Long?') {
return _castInt(type.isNullable);
}
return '$variable as ${_nullsafeKotlinTypeForDartType(type)}';
}

String _castInt(bool isNullable) {
final String nullability = isNullable ? '?' : '';
return 'if (it is Int) it.toLong() else it as Long$nullability';
}
10 changes: 5 additions & 5 deletions packages/pigeon/lib/swift_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ import FlutterMacOS
indent.addScoped('{ $messageVarName, reply in', '}', () {
final List<String> methodArgument = <String>[];
if (components.arguments.isNotEmpty) {
indent.writeln('let args = message as! [Any?]');
indent.writeln('let args = message as! [Any]');
enumerate(components.arguments,
(int index, _SwiftFunctionArgument arg) {
final String argName =
Expand Down Expand Up @@ -668,17 +668,17 @@ String _camelCase(String text) {
}

String _castForceUnwrap(String value, TypeDeclaration type, Root root) {
final String forceUnwrap = type.isNullable ? '' : '!';
if (isEnum(root, type)) {
final String forceUnwrap = type.isNullable ? '' : '!';
final String nullableConditionPrefix =
type.isNullable ? '$value == nil ? nil : ' : '';
return '$nullableConditionPrefix${_swiftTypeForDartType(type)}(rawValue: $value as! Int)$forceUnwrap';
} else if (type.baseName == 'Object') {
// Special-cased to avoid warnings about using 'as' with Any.
return type.isNullable ? value : '$value!';
return value;
} else {
final String castUnwrap = type.isNullable ? '?' : '!';
return '$value as$castUnwrap ${_swiftTypeForDartType(type)}';
final String castUnwrap = type.isNullable ? '?' : '';
return '$value as! ${_swiftTypeForDartType(type)}$castUnwrap';
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/mock_handler_tester/test/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.5), do not edit directly.
// Autogenerated from Pigeon (v9.0.6), 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

Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/mock_handler_tester/test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.5), do not edit directly.
// Autogenerated from Pigeon (v9.0.6), 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.5), do not edit directly.
// Autogenerated from Pigeon (v9.0.6), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package com.example.alternate_language_test_plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.5), do not edit directly.
// Autogenerated from Pigeon (v9.0.6), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import <Foundation/Foundation.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.5), do not edit directly.
// Autogenerated from Pigeon (v9.0.6), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import "CoreTests.gen.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.5), do not edit directly.
// Autogenerated from Pigeon (v9.0.6), 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.5), do not edit directly.
// Autogenerated from Pigeon (v9.0.6), 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.5), do not edit directly.
// Autogenerated from Pigeon (v9.0.6), 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.5), do not edit directly.
// Autogenerated from Pigeon (v9.0.6), 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.5), do not edit directly.
// Autogenerated from Pigeon (v9.0.6), 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.5), do not edit directly.
// Autogenerated from Pigeon (v9.0.6), 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.5), do not edit directly.
// Autogenerated from Pigeon (v9.0.6), 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.5), do not edit directly.
// Autogenerated from Pigeon (v9.0.6), 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

Expand Down
Loading