From 364f98cc53aae49f9f11acb87ebb6c351ea6ac8b Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 4 Jan 2023 19:53:57 -0500 Subject: [PATCH 01/12] Add Object and Object? echos --- packages/pigeon/pigeons/core_tests.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/pigeon/pigeons/core_tests.dart b/packages/pigeon/pigeons/core_tests.dart index 4006d95c133..ed4ba3a3521 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 From ee82c6386f1e69df2aaa28a7866af0fd0198e4f8 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 4 Jan 2023 19:54:15 -0500 Subject: [PATCH 02/12] Fix C++ generator so generation doesn't throw --- packages/pigeon/lib/cpp_generator.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 60fd6ff8b0c..0882bf3c665 100644 --- a/packages/pigeon/lib/cpp_generator.dart +++ b/packages/pigeon/lib/cpp_generator.dart @@ -902,6 +902,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 +932,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&'; } From 145cbfcc473d65d03a84939836e09b4a612f435b Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 4 Jan 2023 19:54:36 -0500 Subject: [PATCH 03/12] Update generated output --- .../CoreTests.java | 73 ++++++++++++-- .../ios/Classes/CoreTests.gen.h | 7 ++ .../ios/Classes/CoreTests.gen.m | 55 +++++++++-- .../lib/src/generated/core_tests.gen.dart | 63 ++++++++++-- .../com/example/test_plugin/CoreTests.gen.kt | 55 ++++++++--- .../ios/Classes/CoreTests.gen.swift | 39 ++++++-- .../macos/Classes/CoreTests.gen.swift | 39 ++++++-- .../windows/pigeon/core_tests.gen.cpp | 95 ++++++++++++++++--- .../windows/pigeon/core_tests.gen.h | 6 ++ 9 files changed, 362 insertions(+), 70 deletions(-) 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 f47ef7d2ad3..2d66c72de31 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 @@ -713,12 +713,9 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { 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 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { 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 interface HostIntegrationCoreApi { /** 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 @@ AllNullableTypes sendMultipleNullableTypes( /** 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 @@ static void setup(BinaryMessenger binaryMessenger, HostIntegrationCoreApi api) { 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 @@ static void setup(BinaryMessenger binaryMessenger, HostIntegrationCoreApi api) { 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/CoreTests.gen.h b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h index 444889c05f4..b2734c7b399 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 @@ -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 81eefa37927..051b2acec5c 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 @@ -220,12 +220,9 @@ - (nullable id)readValueOfType:(UInt8)type { 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 @@ - (void)writeValue:(id)value { if ([value isKindOfClass:[AllNullableTypes class]]) { [self writeByte:128]; [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[AllNullableTypes class]]) { - [self writeByte:129]; - [self writeValue:[value toList]]; } else if ([value isKindOfClass:[AllNullableTypesWrapper class]]) { - [self writeByte:130]; + [self writeByte:129]; [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/src/generated/core_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/core_tests.gen.dart index 2bca40161b1..0ba8803c72a 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 @@ -205,14 +205,11 @@ class _HostIntegrationCoreApiCodec extends StandardMessageCodec { if (value is AllNullableTypes) { buffer.putUint8(128); writeValue(buffer, value.encode()); - } else if (value is AllNullableTypes) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); } else if (value is AllNullableTypesWrapper) { - buffer.putUint8(130); + buffer.putUint8(129); 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] as Object?)!; + } + } + /// 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] as Object?); + } + } + /// 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 a720aa32eb3..0a58442a5ce 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 @@ -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 -> { - stream.write(129) - writeValue(stream, value.toList()) - } is AllNullableTypesWrapper -> { - stream.write(130) + stream.write(129) 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/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index 93a9bcce7c8..31d3262c0f0 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 @@ -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 { - super.writeByte(129) - super.writeValue(value.toList()) } else if let value = value as? AllNullableTypesWrapper { - super.writeByte(130) + super.writeByte(129) 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] as! Any + 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] as? Any + 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/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/CoreTests.gen.swift index 93a9bcce7c8..31d3262c0f0 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 @@ -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 { - super.writeByte(129) - super.writeValue(value.toList()) } else if let value = value as? AllNullableTypesWrapper { - super.writeByte(130) + super.writeByte(129) 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] as! Any + 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] as? Any + 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/windows/pigeon/core_tests.gen.cpp b/packages/pigeon/platform_tests/test_plugin/windows/pigeon/core_tests.gen.cpp index 5f920a4a1c8..4dbcad92c9f 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 @@ -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,44 @@ 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 = + std::get(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 +1216,45 @@ 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 = + std::get_if( + &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 b5b6b450043..b3d7cd6bc68 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 @@ -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( From b0cf2146068eeb4bfc75f2b7074e16908626fba5 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 4 Jan 2023 20:00:20 -0500 Subject: [PATCH 04/12] Add integration test --- .../lib/integration_tests.dart | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) 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 37b4bc843f6..23a46acfdfa 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', () { From cbe1026c59f9ff9c3a645cb7ac809931624ac2cd Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 4 Jan 2023 20:22:41 -0500 Subject: [PATCH 05/12] Implement host sides of new API --- .../AlternateLanguageTestPlugin.java | 10 ++++++++++ .../ios/Classes/AlternateLanguageTestPlugin.m | 9 +++++++++ .../kotlin/com/example/test_plugin/TestPlugin.kt | 13 +++++++++++++ .../test_plugin/ios/Classes/TestPlugin.swift | 8 ++++++++ .../test_plugin/macos/Classes/TestPlugin.swift | 8 ++++++++ .../test_plugin/windows/test_plugin.cpp | 13 +++++++++++++ .../test_plugin/windows/test_plugin.h | 5 ++++- 7 files changed, 65 insertions(+), 1 deletion(-) 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 69910b51379..f0b19118a90 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 byte[] echoUint8List(@NonNull byte[] aUint8List) { 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 byte[] echoUint8List(@NonNull byte[] aUint8List) { 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/ios/Classes/AlternateLanguageTestPlugin.m b/packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.m index ee3e247062c..e81590f1c74 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 @@ - (nullable FlutterStandardTypedData *)echoUint8List:(FlutterStandardTypedData * 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 @@ - (nullable NSString *)echoNullableString:(nullable NSString *)aNullableString 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/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 c5ea2ff4614..1f5441ac2a6 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 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 fun echoNullableObject(aNullableObject: Any?): Any? { + return aNullableObject + } + override fun noopAsync(callback: () -> Unit) { callback() } 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 305627b789f..7170f5f18a9 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/TestPlugin.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift index 85a0f62890e..2cfe48764a7 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/test_plugin.cpp b/packages/pigeon/platform_tests/test_plugin/windows/test_plugin.cpp index b3a3bb110ba..8c35994b98f 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 d5d1e1bd604..1c5bb9d5ff9 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; From 09b9590f3ce3d1092fcac4ee9ddc5e687b794cd2 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 4 Jan 2023 20:42:51 -0500 Subject: [PATCH 06/12] Enable warnings-as-errors for generated Swift code --- .../pigeon/platform_tests/test_plugin/example/ios/Podfile | 4 ++++ .../pigeon/platform_tests/test_plugin/example/macos/Podfile | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/packages/pigeon/platform_tests/test_plugin/example/ios/Podfile b/packages/pigeon/platform_tests/test_plugin/example/ios/Podfile index 211fcba3d00..89720d1a3d3 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 47c1b18feda..aca033923ef 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 From 0421a22918120cdcb1220130136596ca6e139026 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 4 Jan 2023 20:49:14 -0500 Subject: [PATCH 07/12] Fix the warning --- packages/pigeon/lib/swift_generator.dart | 3 +++ .../test_plugin/ios/Classes/CoreTests.gen.swift | 4 ++-- .../test_plugin/macos/Classes/CoreTests.gen.swift | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/pigeon/lib/swift_generator.dart b/packages/pigeon/lib/swift_generator.dart index 3736506c1e7..0311b8de21d 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/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/CoreTests.gen.swift index 31d3262c0f0..cb4a74f1a8d 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 @@ -389,7 +389,7 @@ class HostIntegrationCoreApiSetup { if let api = api { echoObjectChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anObjectArg = args[0] as! Any + let anObjectArg = args[0]! let result = api.echoObject(anObject: anObjectArg) reply(wrapResult(result)) } @@ -501,7 +501,7 @@ class HostIntegrationCoreApiSetup { if let api = api { echoNullableObjectChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aNullableObjectArg = args[0] as? Any + let aNullableObjectArg = args[0] let result = api.echoNullableObject(aNullableObject: aNullableObjectArg) reply(wrapResult(result)) } 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 31d3262c0f0..cb4a74f1a8d 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 @@ -389,7 +389,7 @@ class HostIntegrationCoreApiSetup { if let api = api { echoObjectChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let anObjectArg = args[0] as! Any + let anObjectArg = args[0]! let result = api.echoObject(anObject: anObjectArg) reply(wrapResult(result)) } @@ -501,7 +501,7 @@ class HostIntegrationCoreApiSetup { if let api = api { echoNullableObjectChannel.setMessageHandler { message, reply in let args = message as! [Any?] - let aNullableObjectArg = args[0] as? Any + let aNullableObjectArg = args[0] let result = api.echoNullableObject(aNullableObject: aNullableObjectArg) reply(wrapResult(result)) } From ef2aca1d0e0266be22aa5d3c961144bb1f1f4dfe Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 4 Jan 2023 21:01:50 -0500 Subject: [PATCH 08/12] Version bump --- packages/pigeon/CHANGELOG.md | 5 +++++ packages/pigeon/lib/generator_tools.dart | 2 +- .../example/alternate_language_test_plugin/CoreTests.java | 2 +- .../ios/Classes/CoreTests.gen.h | 2 +- .../ios/Classes/CoreTests.gen.m | 2 +- .../lib/src/generated/core_tests.gen.dart | 2 +- .../src/main/kotlin/com/example/test_plugin/CoreTests.gen.kt | 2 +- .../test_plugin/ios/Classes/CoreTests.gen.swift | 2 +- .../test_plugin/macos/Classes/CoreTests.gen.swift | 2 +- .../test_plugin/windows/pigeon/core_tests.gen.cpp | 2 +- .../test_plugin/windows/pigeon/core_tests.gen.h | 2 +- packages/pigeon/pubspec.yaml | 2 +- 12 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index e0278c5731d..1299c496af3 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,8 @@ +## 4.2.16 + +* [swift] Fixes warnings with `Object` parameters. +* [c++] Generation of APIs that use `Object` no longer fails. + ## 4.2.15 * Relocates generator classes. (Reverted) diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 6624a1dc8ec..ea522eaa04d 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/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 2d66c72de31..c2f03631815 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; 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 b2734c7b399..0e98e89469a 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; 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 051b2acec5c..fa13afaf750 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 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 0ba8803c72a..c6e593034d1 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'; 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 0a58442a5ce..5b33490f65a 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 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 cb4a74f1a8d..b44380ded81 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 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 cb4a74f1a8d..b44380ded81 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 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 4dbcad92c9f..59775daaa34 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 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 b3d7cd6bc68..67b36263a85 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_ diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index e9c9d6b4901..886f56a6ea0 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" From 4e58dd6c9b9298ccb9c10a9ec4c794f614966f71 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 4 Jan 2023 22:55:42 -0500 Subject: [PATCH 09/12] Fix Dart warning exposed by new test --- packages/pigeon/lib/dart_generator.dart | 12 ++++++++---- .../lib/src/generated/core_tests.gen.dart | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/pigeon/lib/dart_generator.dart b/packages/pigeon/lib/dart_generator.dart index 85956ced69e..0500bd4d945 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/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 c6e593034d1..377a02e57f7 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 @@ -507,7 +507,7 @@ class HostIntegrationCoreApi { message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as Object?)!; + return replyList[0]!; } } @@ -735,7 +735,7 @@ class HostIntegrationCoreApi { details: replyList[2], ); } else { - return (replyList[0] as Object?); + return replyList[0]; } } From 4d762c0c4e022d7e718aba671997a3b5496065ff Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 5 Jan 2023 10:36:55 -0500 Subject: [PATCH 10/12] Add Dart to changelog --- packages/pigeon/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 1299c496af3..e286a9c297a 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,6 +1,7 @@ ## 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 From 0c85f860b463f681ff71d85b581f09915cb5e72e Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 5 Jan 2023 10:39:09 -0500 Subject: [PATCH 11/12] Fix Kotlin copypasta --- .../src/main/kotlin/com/example/test_plugin/TestPlugin.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 1f5441ac2a6..b8620dfc913 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,7 +64,7 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi { return aUint8List } - override fun fun echoObject(anObject: Any): Any { + override fun echoObject(anObject: Any): Any { return anObject } @@ -100,7 +100,7 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi { return aNullableUint8List } - override fun fun echoNullableObject(aNullableObject: Any?): Any? { + override fun echoNullableObject(aNullableObject: Any?): Any? { return aNullableObject } From d9944e5f6474ad5776ecaf34a71e49a634741fa8 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Thu, 5 Jan 2023 12:04:39 -0500 Subject: [PATCH 12/12] Fix C++ Object param extraction --- packages/pigeon/lib/cpp_generator.dart | 12 ++++++++ .../windows/pigeon/core_tests.gen.cpp | 6 ++-- packages/pigeon/test/cpp_generator_test.dart | 30 +++++++++++++++++-- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/packages/pigeon/lib/cpp_generator.dart b/packages/pigeon/lib/cpp_generator.dart index 0882bf3c665..7e66600fa49 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);'); 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 59775daaa34..a70c9377311 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 @@ -876,8 +876,7 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, WrapError("an_object_arg unexpectedly null."))); return; } - const auto& an_object_arg = - std::get(encodable_an_object_arg); + const auto& an_object_arg = encodable_an_object_arg; ErrorOr output = api->EchoObject(an_object_arg); if (output.has_error()) { @@ -1231,8 +1230,7 @@ void HostIntegrationCoreApi::SetUp(flutter::BinaryMessenger* binary_messenger, const auto& args = std::get(message); const auto& encodable_a_nullable_object_arg = args.at(0); const auto* a_nullable_object_arg = - std::get_if( - &encodable_a_nullable_object_arg); + &encodable_a_nullable_object_arg; ErrorOr> output = api->EchoNullableObject(a_nullable_object_arg); if (output.has_error()) { diff --git a/packages/pigeon/test/cpp_generator_test.dart b/packages/pigeon/test/cpp_generator_test.dart index d089b0a4480..4733c1f4bf0 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;')); } });