diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index e0278c5731..e286a9c297 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,9 @@ +## 4.2.16 + +* [swift] Fixes warnings with `Object` parameters. +* [dart] Fixes warnings with `Object` return values. +* [c++] Generation of APIs that use `Object` no longer fails. + ## 4.2.15 * Relocates generator classes. (Reverted) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 60fd6ff8b0..7e66600fa4 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -547,6 +547,11 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { // ... then declare the arg as a reference to that local. indent.writeln( 'const auto* $argName = $encodableArgName.IsNull() ? nullptr : &$valueVarName;'); + } else if (hostType.datatype == 'flutter::EncodableValue') { + // Generic objects just pass the EncodableValue through + // directly. + indent.writeln( + 'const auto* $argName = &$encodableArgName;'); } else if (hostType.isBuiltin) { indent.writeln( 'const auto* $argName = std::get_if<${hostType.datatype}>(&$encodableArgName);'); @@ -564,6 +569,13 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() { // requires an int64_t so that it can handle any case. indent.writeln( 'const int64_t $argName = $encodableArgName.LongValue();'); + } else if (hostType.datatype == 'flutter::EncodableValue') { + // Generic objects just pass the EncodableValue through + // directly. This creates an alias just to avoid having to + // special-case the argName/encodableArgName distinction + // at a higher level. + indent + .writeln('const auto& $argName = $encodableArgName;'); } else if (hostType.isBuiltin) { indent.writeln( 'const auto& $argName = std::get<${hostType.datatype}>($encodableArgName);'); @@ -902,6 +914,7 @@ String? _baseCppTypeForBuiltinDartType(TypeDeclaration type) { 'Float64List': 'std::vector', 'Map': 'flutter::EncodableMap', 'List': 'flutter::EncodableList', + 'Object': 'flutter::EncodableValue', }; if (cppTypeForDartTypeMap.containsKey(type.baseName)) { return cppTypeForDartTypeMap[type.baseName]; @@ -931,6 +944,8 @@ String _unownedArgumentType(HostDatatype type) { if (isString || _isPodType(type)) { return type.isNullable ? 'const $baseType*' : baseType; } + // TODO(stuartmorgan): Consider special-casing `Object?` here, so that there + // aren't two ways of representing null (nullptr or an isNull EncodableValue). return type.isNullable ? 'const $baseType*' : 'const $baseType&'; } diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 85956ced69..0500bd4d94 100644 --- a/packages/pigeon/lib/dart_generator.dart +++ b/packages/pigeon/lib/dart_generator.dart @@ -230,13 +230,17 @@ final BinaryMessenger? _binaryMessenger; indent.writeln('binaryMessenger: _binaryMessenger);'); }); final String returnType = _makeGenericTypeArguments(func.returnType); - final String castCall = _makeGenericCastCall(func.returnType); + final String genericCastCall = _makeGenericCastCall(func.returnType); const String accessor = 'replyList[0]'; - final String nullHandler = - func.returnType.isNullable ? (castCall.isEmpty ? '' : '?') : '!'; + // Avoid warnings from pointlessly casting to `Object?`. + final String nullablyTypedAccessor = + returnType == 'Object' ? accessor : '($accessor as $returnType?)'; + final String nullHandler = func.returnType.isNullable + ? (genericCastCall.isEmpty ? '' : '?') + : '!'; final String returnStatement = func.returnType.isVoid ? 'return;' - : 'return ($accessor as $returnType?)$nullHandler$castCall;'; + : 'return $nullablyTypedAccessor$nullHandler$genericCastCall;'; indent.format(''' final List? replyList = \t\tawait channel.send($sendArgument) as List?; diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 6624a1dc8e..ea522eaa04 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -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.15'; +const String pigeonVersion = '4.2.16'; /// Read all the content from [stdin] to a String. String readStdin() { diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 3736506c1e..0311b8de21 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -365,6 +365,9 @@ String _castForceUnwrap(String value, TypeDeclaration type, Root root) { 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!'; } else { final String castUnwrap = type.isNullable ? '?' : '!'; return '$value as$castUnwrap ${_swiftTypeForDartType(type)}'; diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 4006d95c13..ed4ba3a352 100644 --- a/packages/pigeon/pigeons/core_tests.dart +++ b/packages/pigeon/pigeons/core_tests.dart @@ -125,6 +125,10 @@ abstract class HostIntegrationCoreApi { @ObjCSelector('echoUint8List:') Uint8List echoUint8List(Uint8List aUint8List); + /// Returns the passed in generic Object. + @ObjCSelector('echoObject:') + Object echoObject(Object anObject); + // ========== Syncronous nullable method tests ========== /// Returns the inner `aString` value from the wrapped object, to test @@ -162,6 +166,10 @@ abstract class HostIntegrationCoreApi { @ObjCSelector('echoNullableUint8List:') Uint8List? echoNullableUint8List(Uint8List? aNullableUint8List); + /// Returns the passed in generic Object. + @ObjCSelector('echoNullableObject:') + Object? echoNullableObject(Object? aNullableObject); + // ========== Asyncronous method tests ========== /// A no-op function taking no arguments and returning no value, to sanity diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java index 69910b5137..f0b19118a9 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java @@ -72,6 +72,11 @@ public class AlternateLanguageTestPlugin implements FlutterPlugin, HostIntegrati return aUint8List; } + @Override + public @NonNull Object echoObject(@NonNull Object anObject) { + return anObject; + } + @Override public @Nullable String extractNestedNullableString(@NonNull AllNullableTypesWrapper wrapper) { return wrapper.getValues().getANullableString(); @@ -124,6 +129,11 @@ public class AlternateLanguageTestPlugin implements FlutterPlugin, HostIntegrati return aNullableUint8List; } + @Override + public @Nullable Object echoNullableObject(@Nullable Object aNullableObject) { + return aNullableObject; + } + @Override public void noopAsync(Result result) { result.success(null); 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 f47ef7d2ad..c2f0363181 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 (v4.2.15), do not edit directly. +// Autogenerated from Pigeon (v4.2.16), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.alternate_language_test_plugin; @@ -713,12 +713,9 @@ public class CoreTests { return AllNullableTypes.fromList((ArrayList) readValue(buffer)); case (byte) 129: - return AllNullableTypes.fromList((ArrayList) readValue(buffer)); - - case (byte) 130: return AllNullableTypesWrapper.fromList((ArrayList) readValue(buffer)); - case (byte) 131: + case (byte) 130: return AllTypes.fromList((ArrayList) readValue(buffer)); default: @@ -731,14 +728,11 @@ public class CoreTests { if (value instanceof AllNullableTypes) { stream.write(128); writeValue(stream, ((AllNullableTypes) value).toList()); - } else if (value instanceof AllNullableTypes) { - stream.write(129); - writeValue(stream, ((AllNullableTypes) value).toList()); } else if (value instanceof AllNullableTypesWrapper) { - stream.write(130); + stream.write(129); writeValue(stream, ((AllNullableTypesWrapper) value).toList()); } else if (value instanceof AllTypes) { - stream.write(131); + stream.write(130); writeValue(stream, ((AllTypes) value).toList()); } else { super.writeValue(stream, value); @@ -780,6 +774,9 @@ public class CoreTests { /** Returns the passed in Uint8List. */ @NonNull byte[] echoUint8List(@NonNull byte[] aUint8List); + /** Returns the passed in generic Object. */ + @NonNull + Object echoObject(@NonNull Object anObject); /** * Returns the inner `aString` value from the wrapped object, to test sending of nested objects. */ @@ -811,6 +808,9 @@ public class CoreTests { /** Returns the passed in Uint8List. */ @Nullable byte[] echoNullableUint8List(@Nullable byte[] aNullableUint8List); + /** Returns the passed in generic Object. */ + @Nullable + Object echoNullableObject(@Nullable Object aNullableObject); /** * A no-op function taking no arguments and returning no value, to sanity test basic * asynchronous calling. @@ -1072,6 +1072,35 @@ public class CoreTests { channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoObject", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + Object anObjectArg = args.get(0); + if (anObjectArg == null) { + throw new NullPointerException("anObjectArg unexpectedly null."); + } + Object output = api.echoObject(anObjectArg); + wrapped.add(0, output); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -1292,6 +1321,32 @@ public class CoreTests { channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject", + getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList<>(); + try { + ArrayList args = (ArrayList) message; + assert args != null; + Object aNullableObjectArg = args.get(0); + Object output = api.echoNullableObject(aNullableObjectArg); + wrapped.add(0, output); + } catch (Error | RuntimeException exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } { BasicMessageChannel channel = new BasicMessageChannel<>( diff --git a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m index ee3e247062..e81590f1c7 100644 --- a/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m +++ b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m @@ -63,6 +63,10 @@ return aUint8List; } +- (nullable id)echoObject:(id)anObject error:(FlutterError *_Nullable *_Nonnull)error { + return anObject; +} + - (nullable NSString *)extractNestedNullableStringFrom:(AllNullableTypesWrapper *)wrapper error:(FlutterError *_Nullable *_Nonnull)error { return wrapper.values.aNullableString; @@ -114,6 +118,11 @@ return aNullableUint8List; } +- (nullable id)echoNullableObject:(nullable id)aNullableObject + error:(FlutterError *_Nullable *_Nonnull)error { + return aNullableObject; +} + - (void)noopAsyncWithCompletion:(void (^)(FlutterError *_Nullable))completion { completion(nil); } 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 444889c05f..0e98e89469 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 (v4.2.15), do not edit directly. +// Autogenerated from Pigeon (v4.2.16), do not edit directly. // See also: https://pub.dev/packages/pigeon #import @protocol FlutterBinaryMessenger; @@ -131,6 +131,10 @@ NSObject *HostIntegrationCoreApiGetCodec(void); /// @return `nil` only when `error != nil`. - (nullable FlutterStandardTypedData *)echoUint8List:(FlutterStandardTypedData *)aUint8List error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns the passed in generic Object. +/// +/// @return `nil` only when `error != nil`. +- (nullable id)echoObject:(id)anObject error:(FlutterError *_Nullable *_Nonnull)error; /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. - (nullable NSString *)extractNestedNullableStringFrom:(AllNullableTypesWrapper *)wrapper @@ -166,6 +170,9 @@ NSObject *HostIntegrationCoreApiGetCodec(void); - (nullable FlutterStandardTypedData *) echoNullableUint8List:(nullable FlutterStandardTypedData *)aNullableUint8List error:(FlutterError *_Nullable *_Nonnull)error; +/// Returns the passed in generic Object. +- (nullable id)echoNullableObject:(nullable id)aNullableObject + error:(FlutterError *_Nullable *_Nonnull)error; /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. - (void)noopAsyncWithCompletion:(void (^)(FlutterError *_Nullable))completion; 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 81eefa3792..fa13afaf75 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 (v4.2.15), do not edit directly. +// Autogenerated from Pigeon (v4.2.16), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "CoreTests.gen.h" #import @@ -220,12 +220,9 @@ static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { return [AllNullableTypes fromList:[self readValue]]; case 129: - return [AllNullableTypes fromList:[self readValue]]; - - case 130: return [AllNullableTypesWrapper fromList:[self readValue]]; - case 131: + case 130: return [AllTypes fromList:[self readValue]]; default: @@ -241,14 +238,11 @@ static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { if ([value isKindOfClass:[AllNullableTypes class]]) { [self writeByte:128]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllNullableTypes class]]) { + } else if ([value isKindOfClass:[AllNullableTypesWrapper class]]) { [self writeByte:129]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllNullableTypesWrapper class]]) { - [self writeByte:130]; - [self writeValue:[value toList]]; } else if ([value isKindOfClass:[AllTypes class]]) { - [self writeByte:131]; + [self writeByte:130]; [self writeValue:[value toList]]; } else { [super writeValue:value]; @@ -470,6 +464,27 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, [channel setMessageHandler:nil]; } } + /// Returns the passed in generic Object. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.echoObject" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(echoObject:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to @selector(echoObject:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + id arg_anObject = GetNullableObjectAtIndex(args, 0); + FlutterError *error; + id output = [api echoObject:arg_anObject error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. { @@ -656,6 +671,28 @@ void HostIntegrationCoreApiSetup(id binaryMessenger, [channel setMessageHandler:nil]; } } + /// Returns the passed in generic Object. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:@"dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject" + binaryMessenger:binaryMessenger + codec:HostIntegrationCoreApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(echoNullableObject:error:)], + @"HostIntegrationCoreApi api (%@) doesn't respond to " + @"@selector(echoNullableObject:error:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + id arg_aNullableObject = GetNullableObjectAtIndex(args, 0); + FlutterError *error; + id output = [api echoNullableObject:arg_aNullableObject error:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. { diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart index 37b4bc843f..23a46acfdf 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart @@ -351,6 +351,19 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { expect(receivedUint8List, sentUint8List); }); + testWidgets('generic Objects serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + const Object sentString = "I'm a computer"; + final Object receivedString = await api.echoObject(sentString); + expect(receivedString, sentString); + + // Echo a second type as well to ensure the handling is generic. + const Object sentInt = 42; + final Object receivedInt = await api.echoObject(sentInt); + expect(receivedInt, sentInt); + }); + testWidgets('Nullable Ints serialize and deserialize correctly', (WidgetTester _) async { final HostIntegrationCoreApi api = HostIntegrationCoreApi(); @@ -449,6 +462,27 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { await api.echoNullableUint8List(null); expect(receivedNullUint8List, null); }); + + testWidgets('generic nullable Objects serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + const Object sentString = "I'm a computer"; + final Object? receivedString = await api.echoNullableObject(sentString); + expect(receivedString, sentString); + + // Echo a second type as well to ensure the handling is generic. + const Object sentInt = 42; + final Object? receivedInt = await api.echoNullableObject(sentInt); + expect(receivedInt, sentInt); + }); + + testWidgets('Null generic Objects serialize and deserialize correctly', + (WidgetTester _) async { + final HostIntegrationCoreApi api = HostIntegrationCoreApi(); + + final Object? receivedNullObject = await api.echoNullableObject(null); + expect(receivedNullObject, null); + }); }); group('Host async API tests', () { 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 2bca40161b..377a02e57f 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 (v4.2.15), do not edit directly. +// Autogenerated from Pigeon (v4.2.16), 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 import 'dart:async'; @@ -205,14 +205,11 @@ class _HostIntegrationCoreApiCodec extends StandardMessageCodec { if (value is AllNullableTypes) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is AllNullableTypes) { + } else if (value is AllNullableTypesWrapper) { buffer.putUint8(129); writeValue(buffer, value.encode()); - } else if (value is AllNullableTypesWrapper) { - buffer.putUint8(130); - writeValue(buffer, value.encode()); } else if (value is AllTypes) { - buffer.putUint8(131); + buffer.putUint8(130); writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); @@ -226,12 +223,9 @@ class _HostIntegrationCoreApiCodec extends StandardMessageCodec { return AllNullableTypes.decode(readValue(buffer)!); case 129: - return AllNullableTypes.decode(readValue(buffer)!); - - case 130: return AllNullableTypesWrapper.decode(readValue(buffer)!); - case 131: + case 130: return AllTypes.decode(readValue(buffer)!); default: @@ -489,6 +483,34 @@ class HostIntegrationCoreApi { } } + /// Returns the passed in generic Object. + Future echoObject(Object arg_anObject) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.echoObject', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_anObject]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return replyList[0]!; + } + } + /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. Future extractNestedNullableString( @@ -694,6 +716,29 @@ class HostIntegrationCoreApi { } } + /// Returns the passed in generic Object. + Future echoNullableObject(Object? arg_aNullableObject) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject', codec, + binaryMessenger: _binaryMessenger); + final List? replyList = + await channel.send([arg_aNullableObject]) as List?; + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else { + return replyList[0]; + } + } + /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. Future noopAsync() async { 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 a720aa32eb..5b33490f65 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 (v4.2.15), do not edit directly. +// Autogenerated from Pigeon (v4.2.16), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.example.test_plugin @@ -169,16 +169,11 @@ private object HostIntegrationCoreApiCodec : StandardMessageCodec() { } } 129.toByte() -> { - return (readValue(buffer) as? List)?.let { - AllNullableTypes.fromList(it) - } - } - 130.toByte() -> { return (readValue(buffer) as? List)?.let { AllNullableTypesWrapper.fromList(it) } } - 131.toByte() -> { + 130.toByte() -> { return (readValue(buffer) as? List)?.let { AllTypes.fromList(it) } @@ -192,16 +187,12 @@ private object HostIntegrationCoreApiCodec : StandardMessageCodec() { stream.write(128) writeValue(stream, value.toList()) } - is AllNullableTypes -> { + is AllNullableTypesWrapper -> { stream.write(129) writeValue(stream, value.toList()) } - is AllNullableTypesWrapper -> { - stream.write(130) - writeValue(stream, value.toList()) - } is AllTypes -> { - stream.write(131) + stream.write(130) writeValue(stream, value.toList()) } else -> super.writeValue(stream, value) @@ -237,6 +228,8 @@ interface HostIntegrationCoreApi { fun echoString(aString: String): String /** Returns the passed in Uint8List. */ fun echoUint8List(aUint8List: ByteArray): ByteArray + /** Returns the passed in generic Object. */ + fun echoObject(anObject: Any): Any /** * Returns the inner `aString` value from the wrapped object, to test * sending of nested objects. @@ -259,6 +252,8 @@ interface HostIntegrationCoreApi { fun echoNullableString(aNullableString: String?): String? /** Returns the passed in Uint8List. */ fun echoNullableUint8List(aNullableUint8List: ByteArray?): ByteArray? + /** Returns the passed in generic Object. */ + fun echoNullableObject(aNullableObject: Any?): Any? /** * A no-op function taking no arguments and returning no value, to sanity * test basic asynchronous calling. @@ -437,6 +432,24 @@ interface HostIntegrationCoreApi { channel.setMessageHandler(null) } } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.echoObject", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val anObjectArg = args[0] as Any + wrapped = listOf(api.echoObject(anObjectArg)) + } catch (exception: Error) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } run { val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.extractNestedNullableString", codec) if (api != null) { @@ -583,6 +596,24 @@ interface HostIntegrationCoreApi { channel.setMessageHandler(null) } } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + var wrapped = listOf() + try { + val args = message as List + val aNullableObjectArg = args[0] as? Any + wrapped = listOf(api.echoNullableObject(aNullableObjectArg)) + } catch (exception: Error) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } run { val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.HostIntegrationCoreApi.noopAsync", codec) if (api != null) { diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt index c5ea2ff461..b8620dfc91 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/TestPlugin.kt @@ -64,6 +64,10 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi { return aUint8List } + override fun echoObject(anObject: Any): Any { + return anObject + } + override fun extractNestedNullableString(wrapper: AllNullableTypesWrapper): String? { return wrapper.values.aNullableString } @@ -75,22 +79,31 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi { override fun sendMultipleNullableTypes(aNullableBool: Boolean?, aNullableInt: Long?, aNullableString: String?): AllNullableTypes { return AllNullableTypes(aNullableBool = aNullableBool, aNullableInt = aNullableInt, aNullableString = aNullableString) } + override fun echoNullableInt(aNullableInt: Long?): Long? { return aNullableInt } + override fun echoNullableDouble(aNullableDouble: Double?): Double? { return aNullableDouble } + override fun echoNullableBool(aNullableBool: Boolean?): Boolean? { return aNullableBool } + override fun echoNullableString(aNullableString: String?): String? { return aNullableString } + override fun echoNullableUint8List(aNullableUint8List: ByteArray?): ByteArray? { return aNullableUint8List } + override fun echoNullableObject(aNullableObject: Any?): Any? { + return aNullableObject + } + override fun noopAsync(callback: () -> Unit) { callback() } diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/Podfile b/packages/pigeon/platform_tests/test_plugin/example/ios/Podfile index 211fcba3d0..89720d1a3d 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/ios/Podfile +++ b/packages/pigeon/platform_tests/test_plugin/example/ios/Podfile @@ -41,5 +41,9 @@ end post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) + + target.build_configurations.each do |config| + config.build_settings['SWIFT_TREAT_WARNINGS_AS_ERRORS'] = 'YES' + end end end diff --git a/packages/pigeon/platform_tests/test_plugin/example/macos/Podfile b/packages/pigeon/platform_tests/test_plugin/example/macos/Podfile index 47c1b18fed..aca033923e 100644 --- a/packages/pigeon/platform_tests/test_plugin/example/macos/Podfile +++ b/packages/pigeon/platform_tests/test_plugin/example/macos/Podfile @@ -40,5 +40,9 @@ end post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_macos_build_settings(target) + + target.build_configurations.each do |config| + config.build_settings['SWIFT_TREAT_WARNINGS_AS_ERRORS'] = 'YES' + end end end 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 93a9bcce7c..b44380ded8 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 (v4.2.15), do not edit directly. +// Autogenerated from Pigeon (v4.2.16), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -178,10 +178,8 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader { case 128: return AllNullableTypes.fromList(self.readValue() as! [Any]) case 129: - return AllNullableTypes.fromList(self.readValue() as! [Any]) - case 130: return AllNullableTypesWrapper.fromList(self.readValue() as! [Any]) - case 131: + case 130: return AllTypes.fromList(self.readValue() as! [Any]) default: return super.readValue(ofType: type) @@ -194,14 +192,11 @@ private class HostIntegrationCoreApiCodecWriter: FlutterStandardWriter { if let value = value as? AllNullableTypes { super.writeByte(128) super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypes { + } else if let value = value as? AllNullableTypesWrapper { super.writeByte(129) super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypesWrapper { - super.writeByte(130) - super.writeValue(value.toList()) } else if let value = value as? AllTypes { - super.writeByte(131) + super.writeByte(130) super.writeValue(value.toList()) } else { super.writeValue(value) @@ -247,6 +242,8 @@ protocol HostIntegrationCoreApi { func echoString(aString: String) -> String /// Returns the passed in Uint8List. func echoUint8List(aUint8List: FlutterStandardTypedData) -> FlutterStandardTypedData + /// Returns the passed in generic Object. + func echoObject(anObject: Any) -> Any /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. func extractNestedNullableString(wrapper: AllNullableTypesWrapper) -> String? @@ -265,6 +262,8 @@ protocol HostIntegrationCoreApi { func echoNullableString(aNullableString: String?) -> String? /// Returns the passed in Uint8List. func echoNullableUint8List(aNullableUint8List: FlutterStandardTypedData?) -> FlutterStandardTypedData? + /// Returns the passed in generic Object. + func echoNullableObject(aNullableObject: Any?) -> Any? /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. func noopAsync(completion: @escaping () -> Void) @@ -385,6 +384,18 @@ class HostIntegrationCoreApiSetup { } else { echoUint8ListChannel.setMessageHandler(nil) } + /// Returns the passed in generic Object. + let echoObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoObject", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let anObjectArg = args[0]! + let result = api.echoObject(anObject: anObjectArg) + reply(wrapResult(result)) + } + } else { + echoObjectChannel.setMessageHandler(nil) + } /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. let extractNestedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.extractNestedNullableString", binaryMessenger: binaryMessenger, codec: codec) @@ -485,6 +496,18 @@ class HostIntegrationCoreApiSetup { } else { echoNullableUint8ListChannel.setMessageHandler(nil) } + /// Returns the passed in generic Object. + let echoNullableObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableObjectArg = args[0] + let result = api.echoNullableObject(aNullableObject: aNullableObjectArg) + reply(wrapResult(result)) + } + } else { + echoNullableObjectChannel.setMessageHandler(nil) + } /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. let noopAsyncChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec) 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 305627b789..7170f5f18a 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -59,6 +59,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return aUint8List } + func echoObject(anObject: Any) -> Any { + return anObject + } + func extractNestedNullableString(wrapper: AllNullableTypesWrapper) -> String? { return wrapper.values.aNullableString; } @@ -92,6 +96,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return aNullableUint8List } + func echoNullableObject(aNullableObject: Any?) -> Any? { + return aNullableObject + } + func noopAsync(completion: @escaping () -> Void) { completion() } 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 93a9bcce7c..b44380ded8 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 (v4.2.15), do not edit directly. +// Autogenerated from Pigeon (v4.2.16), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -178,10 +178,8 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader { case 128: return AllNullableTypes.fromList(self.readValue() as! [Any]) case 129: - return AllNullableTypes.fromList(self.readValue() as! [Any]) - case 130: return AllNullableTypesWrapper.fromList(self.readValue() as! [Any]) - case 131: + case 130: return AllTypes.fromList(self.readValue() as! [Any]) default: return super.readValue(ofType: type) @@ -194,14 +192,11 @@ private class HostIntegrationCoreApiCodecWriter: FlutterStandardWriter { if let value = value as? AllNullableTypes { super.writeByte(128) super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypes { + } else if let value = value as? AllNullableTypesWrapper { super.writeByte(129) super.writeValue(value.toList()) - } else if let value = value as? AllNullableTypesWrapper { - super.writeByte(130) - super.writeValue(value.toList()) } else if let value = value as? AllTypes { - super.writeByte(131) + super.writeByte(130) super.writeValue(value.toList()) } else { super.writeValue(value) @@ -247,6 +242,8 @@ protocol HostIntegrationCoreApi { func echoString(aString: String) -> String /// Returns the passed in Uint8List. func echoUint8List(aUint8List: FlutterStandardTypedData) -> FlutterStandardTypedData + /// Returns the passed in generic Object. + func echoObject(anObject: Any) -> Any /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. func extractNestedNullableString(wrapper: AllNullableTypesWrapper) -> String? @@ -265,6 +262,8 @@ protocol HostIntegrationCoreApi { func echoNullableString(aNullableString: String?) -> String? /// Returns the passed in Uint8List. func echoNullableUint8List(aNullableUint8List: FlutterStandardTypedData?) -> FlutterStandardTypedData? + /// Returns the passed in generic Object. + func echoNullableObject(aNullableObject: Any?) -> Any? /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. func noopAsync(completion: @escaping () -> Void) @@ -385,6 +384,18 @@ class HostIntegrationCoreApiSetup { } else { echoUint8ListChannel.setMessageHandler(nil) } + /// Returns the passed in generic Object. + let echoObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoObject", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let anObjectArg = args[0]! + let result = api.echoObject(anObject: anObjectArg) + reply(wrapResult(result)) + } + } else { + echoObjectChannel.setMessageHandler(nil) + } /// Returns the inner `aString` value from the wrapped object, to test /// sending of nested objects. let extractNestedNullableStringChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.extractNestedNullableString", binaryMessenger: binaryMessenger, codec: codec) @@ -485,6 +496,18 @@ class HostIntegrationCoreApiSetup { } else { echoNullableUint8ListChannel.setMessageHandler(nil) } + /// Returns the passed in generic Object. + let echoNullableObjectChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject", binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + echoNullableObjectChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let aNullableObjectArg = args[0] + let result = api.echoNullableObject(aNullableObject: aNullableObjectArg) + reply(wrapResult(result)) + } + } else { + echoNullableObjectChannel.setMessageHandler(nil) + } /// A no-op function taking no arguments and returning no value, to sanity /// test basic asynchronous calling. let noopAsyncChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.HostIntegrationCoreApi.noopAsync", binaryMessenger: binaryMessenger, codec: codec) diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift index 85a0f62890..2cfe48764a 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -59,6 +59,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return aUint8List } + func echoObject(anObject: Any) -> Any { + return anObject + } + func extractNestedNullableString(wrapper: AllNullableTypesWrapper) -> String? { return wrapper.values.aNullableString; } @@ -92,6 +96,10 @@ public class TestPlugin: NSObject, FlutterPlugin, HostIntegrationCoreApi { return aNullableUint8List } + func echoNullableObject(aNullableObject: Any?) -> Any? { + return aNullableObject + } + func noopAsync(completion: @escaping () -> Void) { completion() } 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 5f920a4a1c..a70c937731 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 (v4.2.15), do not edit directly. +// Autogenerated from Pigeon (v4.2.16), do not edit directly. // See also: https://pub.dev/packages/pigeon #undef _HAS_EXCEPTIONS @@ -490,14 +490,10 @@ flutter::EncodableValue HostIntegrationCoreApiCodecSerializer::ReadValueOfType( std::get(ReadValue(stream)))); case 129: - return flutter::CustomEncodableValue(AllNullableTypes( - std::get(ReadValue(stream)))); - - case 130: return flutter::CustomEncodableValue(AllNullableTypesWrapper( std::get(ReadValue(stream)))); - case 131: + case 130: return flutter::CustomEncodableValue( AllTypes(std::get(ReadValue(stream)))); @@ -519,16 +515,8 @@ void HostIntegrationCoreApiCodecSerializer::WriteValue( stream); return; } - if (custom_value->type() == typeid(AllNullableTypes)) { - stream->WriteByte(129); - WriteValue( - flutter::EncodableValue( - std::any_cast(*custom_value).ToEncodableList()), - stream); - return; - } if (custom_value->type() == typeid(AllNullableTypesWrapper)) { - stream->WriteByte(130); + stream->WriteByte(129); WriteValue(flutter::EncodableValue( std::any_cast(*custom_value) .ToEncodableList()), @@ -536,7 +524,7 @@ void HostIntegrationCoreApiCodecSerializer::WriteValue( return; } if (custom_value->type() == typeid(AllTypes)) { - stream->WriteByte(131); + stream->WriteByte(130); WriteValue(flutter::EncodableValue( std::any_cast(*custom_value).ToEncodableList()), stream); @@ -869,6 +857,43 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, channel->SetMessageHandler(nullptr); } } + { + auto channel = + std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoObject", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + flutter::EncodableList wrapped; + try { + const auto& args = std::get(message); + const auto& encodable_an_object_arg = args.at(0); + if (encodable_an_object_arg.IsNull()) { + reply(flutter::EncodableValue( + WrapError("an_object_arg unexpectedly null."))); + return; + } + const auto& an_object_arg = encodable_an_object_arg; + ErrorOr output = + api->EchoObject(an_object_arg); + if (output.has_error()) { + wrapped = WrapError(output.error()); + } else { + wrapped.push_back( + flutter::EncodableValue(std::move(output).TakeValue())); + } + } catch (const std::exception& exception) { + wrapped = WrapError(exception.what()); + } + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } else { + channel->SetMessageHandler(nullptr); + } + } { auto channel = std::make_unique< flutter::BasicMessageChannel>( @@ -1190,6 +1215,44 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, channel->SetMessageHandler(nullptr); } } + { + auto channel = + std::make_unique>( + binary_messenger, + "dev.flutter.pigeon.HostIntegrationCoreApi.echoNullableObject", + &GetCodec()); + if (api != nullptr) { + channel->SetMessageHandler( + [api](const flutter::EncodableValue& message, + const flutter::MessageReply& reply) { + flutter::EncodableList wrapped; + try { + const auto& args = std::get(message); + const auto& encodable_a_nullable_object_arg = args.at(0); + const auto* a_nullable_object_arg = + &encodable_a_nullable_object_arg; + ErrorOr> output = + api->EchoNullableObject(a_nullable_object_arg); + if (output.has_error()) { + wrapped = WrapError(output.error()); + } else { + auto output_optional = std::move(output).TakeValue(); + if (output_optional) { + wrapped.push_back(flutter::EncodableValue( + std::move(output_optional).value())); + } else { + wrapped.push_back(flutter::EncodableValue()); + } + } + } catch (const std::exception& exception) { + wrapped = WrapError(exception.what()); + } + reply(flutter::EncodableValue(std::move(wrapped))); + }); + } else { + channel->SetMessageHandler(nullptr); + } + } { auto channel = std::make_unique>( 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 b5b6b45004..67b36263a8 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 (v4.2.15), do not edit directly. +// Autogenerated from Pigeon (v4.2.16), do not edit directly. // See also: https://pub.dev/packages/pigeon #ifndef PIGEON_CORE_TESTS_GEN_CORE_TESTS_PIGEONTEST_H_ @@ -283,6 +283,9 @@ class HostIntegrationCoreApi { // Returns the passed in Uint8List. virtual ErrorOr> EchoUint8List( const std::vector& a_uint8_list) = 0; + // Returns the passed in generic Object. + virtual ErrorOr EchoObject( + const flutter::EncodableValue& an_object) = 0; // Returns the inner `aString` value from the wrapped object, to test // sending of nested objects. virtual ErrorOr> ExtractNestedNullableString( @@ -310,6 +313,9 @@ class HostIntegrationCoreApi { // Returns the passed in Uint8List. virtual ErrorOr>> EchoNullableUint8List( const std::vector* a_nullable_uint8_list) = 0; + // Returns the passed in generic Object. + virtual ErrorOr> EchoNullableObject( + const flutter::EncodableValue* a_nullable_object) = 0; // A no-op function taking no arguments and returning no value, to sanity // test basic asynchronous calling. virtual void NoopAsync( diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp index b3a3bb110b..8c35994b98 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp @@ -73,6 +73,11 @@ ErrorOr> TestPlugin::EchoUint8List( return a_uint8_list; } +ErrorOr TestPlugin::EchoObject( + const flutter::EncodableValue& an_object) { + return an_object; +} + ErrorOr> TestPlugin::ExtractNestedNullableString( const AllNullableTypesWrapper& wrapper) { const std::string* inner_string = wrapper.values().a_nullable_string(); @@ -153,6 +158,14 @@ ErrorOr>> TestPlugin::EchoNullableUint8List( return *a_nullable_uint8_list; }; +ErrorOr> TestPlugin::EchoNullableObject( + const flutter::EncodableValue* a_nullable_object) { + if (!a_nullable_object) { + return std::nullopt; + } + return *a_nullable_object; +}; + void TestPlugin::NoopAsync( std::function reply)> result) { result(std::nullopt); diff --git a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h index d5d1e1bd60..1c5bb9d5ff 100644 --- a/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h +++ b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.h @@ -47,6 +47,8 @@ class TestPlugin : public flutter::Plugin, const std::string& a_string) override; core_tests_pigeontest::ErrorOr> EchoUint8List( const std::vector& a_uint8_list) override; + core_tests_pigeontest::ErrorOr EchoObject( + const flutter::EncodableValue& an_object) override; core_tests_pigeontest::ErrorOr> ExtractNestedNullableString( const core_tests_pigeontest::AllNullableTypesWrapper& wrapper) override; @@ -67,7 +69,8 @@ class TestPlugin : public flutter::Plugin, core_tests_pigeontest::ErrorOr>> EchoNullableUint8List( const std::vector* a_nullable_uint8_list) override; - + core_tests_pigeontest::ErrorOr> + EchoNullableObject(const flutter::EncodableValue* a_nullable_object) override; void NoopAsync(std::function< void(std::optional reply)> result) override; diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index e9c9d6b490..886f56a6ea 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: 4.2.15 # This must match the version in lib/generator_tools.dart +version: 4.2.16 # This must match the version in lib/generator_tools.dart environment: sdk: ">=2.12.0 <3.0.0" diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index d089b0a448..4733c1f4bf 100644 --- a/packages/pigeon/test/cpp_generator_test.dart +++ b/packages/pigeon/test/cpp_generator_test.dart @@ -809,6 +809,12 @@ void main() { baseName: 'ParameterObject', isNullable: true, )), + NamedType( + name: 'aGenericObject', + type: const TypeDeclaration( + baseName: 'Object', + isNullable: true, + )), ], returnType: const TypeDeclaration.voidDeclaration(), ), @@ -834,7 +840,8 @@ void main() { 'const std::string* a_string, ' 'const flutter::EncodableList* a_list, ' 'const flutter::EncodableMap* a_map, ' - 'const ParameterObject* an_object)')); + 'const ParameterObject* an_object, ' + 'const flutter::EncodableValue* a_generic_object)')); } { final StringBuffer sink = StringBuffer(); @@ -875,6 +882,12 @@ void main() { code, contains( 'const auto* an_object_arg = &(std::any_cast(std::get(encodable_an_object_arg)));')); + // "Object" requires no extraction at all since it has to use + // EncodableValue directly. + expect( + code, + contains( + 'const auto* a_generic_object_arg = &encodable_a_generic_object_arg;')); } }); @@ -927,6 +940,12 @@ void main() { baseName: 'ParameterObject', isNullable: false, )), + NamedType( + name: 'aGenericObject', + type: const TypeDeclaration( + baseName: 'Object', + isNullable: false, + )), ], returnType: const TypeDeclaration.voidDeclaration(), ), @@ -952,7 +971,8 @@ void main() { 'const std::string& a_string, ' 'const flutter::EncodableList& a_list, ' 'const flutter::EncodableMap& a_map, ' - 'const ParameterObject& an_object)')); + 'const ParameterObject& an_object, ' + 'const flutter::EncodableValue& a_generic_object)')); } { final StringBuffer sink = StringBuffer(); @@ -988,6 +1008,12 @@ void main() { code, contains( 'const auto& an_object_arg = std::any_cast(std::get(encodable_an_object_arg));')); + // "Object" requires no extraction at all since it has to use + // EncodableValue directly. + expect( + code, + contains( + 'const auto& a_generic_object_arg = encodable_a_generic_object_arg;')); } });