Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pigeon] Fix missed casting of not nullable Dart int to Kotlin long #3004

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 7.0.2

* [kotlin] Fixes a missed casting of not nullable Dart 'int' to Kotlin 64bit long.

## 7.0.1

* [generator_tools] adds `newln` method for adding empty lines and ending lines.
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 @@ -9,7 +9,7 @@ import 'dart:mirrors';
import 'ast.dart';

/// The current version of pigeon. This must match the version in pubspec.yaml.
const String pigeonVersion = '7.0.1';
const String pigeonVersion = '7.0.2';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
4 changes: 4 additions & 0 deletions packages/pigeon/lib/kotlin_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
customEnumNames.contains(field.type.baseName)) {
indent.writeln(
'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 }');
} else {
indent.writeln('val ${field.name} = $listValue as $fieldType');
}
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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.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

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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.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
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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.0.2), 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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.0.2), 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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.0.2), 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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.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

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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.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

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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.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

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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.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

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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.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

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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.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

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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) {
expect(listEquals(echoObject.aList, genericAllTypes.aList), true);
expect(mapEquals(echoObject.aMap, genericAllTypes.aMap), true);
expect(echoObject.anEnum, genericAllTypes.anEnum);
},
// TODO(stuartmorgan): Fix and re-enable.
// See https://github.com/flutter/flutter/issues/118726
skip: targetGenerator == TargetGenerator.kotlin);
});

testWidgets('all nullable datatypes serialize and deserialize correctly',
(WidgetTester _) async {
Expand Down Expand Up @@ -531,11 +528,8 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) {
expect(echoObject.anEnum, genericAllTypes.anEnum);
},
// TODO(stuartmorgan): Fix and re-enable.
// See https://github.com/flutter/flutter/issues/118726
skip: targetGenerator == TargetGenerator.kotlin ||
// TODO(stuartmorgan): Fix and re-enable.
// See https://github.com/flutter/flutter/issues/118739
targetGenerator == TargetGenerator.cpp);
// See https://github.com/flutter/flutter/issues/118739
skip: targetGenerator == TargetGenerator.cpp);

testWidgets(
'Arguments of multiple types serialize and deserialize correctly',
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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.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

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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package com.example.test_plugin
Expand Down Expand Up @@ -58,7 +58,7 @@ data class AllTypes (
@Suppress("UNCHECKED_CAST")
fun fromList(list: List<Any?>): AllTypes {
val aBool = list[0] as Boolean
val anInt = list[1] as Long
val anInt = list[1].let { if (it is Int) it.toLong() else it as Long }
val aDouble = list[2] as Double
val aByteArray = list[3] as ByteArray
val a4ByteArray = list[4] as IntArray
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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

import Foundation
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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

import Foundation
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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#undef _HAS_EXCEPTIONS
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 (v7.0.1), do not edit directly.
// Autogenerated from Pigeon (v7.0.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#ifndef PIGEON_CORE_TESTS_GEN_H_
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 7.0.1 # This must match the version in lib/generator_tools.dart
version: 7.0.2 # This must match the version in lib/generator_tools.dart

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
102 changes: 87 additions & 15 deletions packages/pigeon/test/kotlin_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,28 +207,28 @@ void main() {
NamedType(
type: const TypeDeclaration(
baseName: 'bool',
isNullable: true,
isNullable: false,
),
name: 'aBool',
),
NamedType(
type: const TypeDeclaration(
baseName: 'int',
isNullable: true,
isNullable: false,
),
name: 'aInt',
),
NamedType(
type: const TypeDeclaration(
baseName: 'double',
isNullable: true,
isNullable: false,
),
name: 'aDouble',
),
NamedType(
type: const TypeDeclaration(
baseName: 'String',
isNullable: true,
isNullable: false,
),
name: 'aString',
),
Expand All @@ -242,24 +242,80 @@ void main() {
NamedType(
type: const TypeDeclaration(
baseName: 'Int32List',
isNullable: true,
isNullable: false,
),
name: 'aInt32List',
),
NamedType(
type: const TypeDeclaration(
baseName: 'Int64List',
isNullable: true,
isNullable: false,
),
name: 'aInt64List',
),
NamedType(
type: const TypeDeclaration(
baseName: 'Float64List',
isNullable: true,
isNullable: false,
),
name: 'aFloat64List',
),
NamedType(
type: const TypeDeclaration(
baseName: 'bool',
isNullable: true,
),
name: 'aNullableBool',
),
NamedType(
type: const TypeDeclaration(
baseName: 'int',
isNullable: true,
),
name: 'aNullableInt',
),
NamedType(
type: const TypeDeclaration(
baseName: 'double',
isNullable: true,
),
name: 'aNullableDouble',
),
NamedType(
type: const TypeDeclaration(
baseName: 'String',
isNullable: true,
),
name: 'aNullableString',
),
NamedType(
type: const TypeDeclaration(
baseName: 'Uint8List',
isNullable: true,
),
name: 'aNullableUint8List',
),
NamedType(
type: const TypeDeclaration(
baseName: 'Int32List',
isNullable: true,
),
name: 'aNullableInt32List',
),
NamedType(
type: const TypeDeclaration(
baseName: 'Int64List',
isNullable: true,
),
name: 'aNullableInt64List',
),
NamedType(
type: const TypeDeclaration(
baseName: 'Float64List',
isNullable: true,
),
name: 'aNullableFloat64List',
),
]),
], enums: <Enum>[]);

Expand All @@ -269,14 +325,30 @@ void main() {
const KotlinGenerator generator = KotlinGenerator();
generator.generate(kotlinOptions, root, sink);
final String code = sink.toString();
expect(code, contains('val aBool: Boolean? = null'));
expect(code, contains('val aInt: Long? = null'));
expect(code, contains('val aDouble: Double? = null'));
expect(code, contains('val aString: String? = null'));
expect(code, contains('val aUint8List: ByteArray? = null'));
expect(code, contains('val aInt32List: IntArray? = null'));
expect(code, contains('val aInt64List: LongArray? = null'));
expect(code, contains('val aFloat64List: DoubleArray? = null'));
expect(code, contains('val aBool: Boolean'));
expect(code, contains('val aInt: Long'));
expect(code, contains('val aDouble: Double'));
expect(code, contains('val aString: String'));
expect(code, contains('val aUint8List: ByteArray'));
expect(code, contains('val aInt32List: IntArray'));
expect(code, contains('val aInt64List: LongArray'));
expect(code, contains('val aFloat64List: DoubleArray'));
expect(
code,
contains(
'val aInt = list[1].let { if (it is Int) it.toLong() else it as Long }'));
expect(code, contains('val aNullableBool: Boolean? = null'));
expect(code, contains('val aNullableInt: Long? = null'));
expect(code, contains('val aNullableDouble: Double? = null'));
expect(code, contains('val aNullableString: String? = null'));
expect(code, contains('val aNullableUint8List: ByteArray? = null'));
expect(code, contains('val aNullableInt32List: IntArray? = null'));
expect(code, contains('val aNullableInt64List: LongArray? = null'));
expect(code, contains('val aNullableFloat64List: DoubleArray? = null'));
expect(
code,
contains(
'val aNullableInt = list[9].let { if (it is Int) it.toLong() else it as? Long }'));
});

test('gen one flutter api', () {
Expand Down