[pigeon] Fix Kotlin generated sync host api error (#2693)

This commit is contained in:
J!nl!n
2022-10-31 22:14:17 +08:00
committed by GitHub
parent ffb95bfeee
commit c477caa30b
5 changed files with 25 additions and 4 deletions

View File

@ -1,3 +1,7 @@
## 4.2.4
* [kotlin] Fixes Kotlin generated sync host api error.
## 4.2.3
* [java] Adds assert `args != null`.

View File

@ -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 = '4.2.3';
const String pigeonVersion = '4.2.4';
/// Read all the content from [stdin] to a String.
String readStdin() {

View File

@ -250,7 +250,7 @@ void _writeHostApi(Indent indent, Api api, Root root) {
}
}, addTrailingNewline: false);
indent.add(' catch (exception: Error) ');
indent.scoped('{', '', () {
indent.scoped('{', '}', () {
indent.writeln(
'wrapped["${Keys.error}"] = wrapError(exception)');
if (method.isAsynchronous) {
@ -262,7 +262,7 @@ void _writeHostApi(Indent indent, Api api, Root root) {
}
});
}, addTrailingNewline: false);
indent.scoped('} else {', '}', () {
indent.scoped(' else {', '}', () {
indent.writeln('channel.setMessageHandler(null)');
});
});

View File

@ -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: 4.2.3 # This must match the version in lib/generator_tools.dart
version: 4.2.4 # This must match the version in lib/generator_tools.dart
environment:
sdk: ">=2.12.0 <3.0.0"

View File

@ -126,6 +126,23 @@ void main() {
expect(code, contains('interface Api'));
expect(code, contains('fun doSomething(input: Input): Output'));
expect(code, contains('channel.setMessageHandler'));
expect(code, contains('''
if (api != null) {
channel.setMessageHandler { message, reply ->
val wrapped = hashMapOf<String, Any?>()
try {
val args = message as List<Any?>
val inputArg = args[0] as Input
wrapped["result"] = api.doSomething(inputArg)
} catch (exception: Error) {
wrapped["error"] = wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
'''));
});
test('all the simple datatypes header', () {