diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index cd80620dadde..62e96ff707b5 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,7 @@ +## 22.6.4 + +* [swift] Fixes the channel names of the named constructors of ProxyApis. + ## 22.6.3 * Replaces deprecated collection method usage. diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index 6c468902eda9..436279827604 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -14,7 +14,7 @@ import 'ast.dart'; /// The current version of pigeon. /// /// This must match the version in pubspec.yaml. -const String pigeonVersion = '22.6.3'; +const String pigeonVersion = '22.6.4'; /// 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 596ae4050155..417c93e95448 100644 --- a/packages/pigeon/lib/swift_generator.dart +++ b/packages/pigeon/lib/swift_generator.dart @@ -2012,7 +2012,9 @@ private func nilOrValue(_ value: Any?) -> T? { : 'pigeonDefaultConstructor'; final String channelName = makeChannelNameWithStrings( apiName: api.name, - methodName: '${classMemberNamePrefix}defaultConstructor', + methodName: constructor.name.isNotEmpty + ? constructor.name + : '${classMemberNamePrefix}defaultConstructor', dartPackageName: dartPackageName, ); writeWithApiCheckIfNecessary( diff --git a/packages/pigeon/pigeons/proxy_api_tests.dart b/packages/pigeon/pigeons/proxy_api_tests.dart index 0e7bfed75ff6..b9e001071bd0 100644 --- a/packages/pigeon/pigeons/proxy_api_tests.dart +++ b/packages/pigeon/pigeons/proxy_api_tests.dart @@ -54,6 +54,8 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass ProxyApiSuperClass? nullableProxyApiParam, ); + ProxyApiTestClass.namedConstructor(); + late bool aBool; late int anInt; late double aDouble; 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 21d76637675c..3289142840da 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 @@ -2170,6 +2170,22 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) { return; } + testWidgets('named constructor', (_) async { + final ProxyApiTestClass instance = ProxyApiTestClass.namedConstructor( + aBool: true, + anInt: 0, + aDouble: 0.0, + aString: '', + aUint8List: Uint8List(0), + aList: const [], + aMap: const {}, + anEnum: ProxyApiTestEnum.one, + aProxyApi: ProxyApiSuperClass(), + ); + // Ensure no error calling method on instance. + await instance.noop(); + }); + testWidgets('noop', (_) async { final ProxyApiTestClass api = _createGenericProxyApiTestClass(); diff --git a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart index 667eac6910b6..a371c3333497 100644 --- a/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart +++ b/packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart @@ -578,6 +578,104 @@ class ProxyApiTestClass extends ProxyApiSuperClass }(); } + ProxyApiTestClass.namedConstructor({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.aBool, + required this.anInt, + required this.aDouble, + required this.aString, + required this.aUint8List, + required this.aList, + required this.aMap, + required this.anEnum, + required this.aProxyApi, + this.aNullableBool, + this.aNullableInt, + this.aNullableDouble, + this.aNullableString, + this.aNullableUint8List, + this.aNullableList, + this.aNullableMap, + this.aNullableEnum, + this.aNullableProxyApi, + this.anInterfaceMethod, + this.flutterNoop, + this.flutterThrowError, + this.flutterThrowErrorFromVoid, + this.flutterEchoBool, + this.flutterEchoInt, + this.flutterEchoDouble, + this.flutterEchoString, + this.flutterEchoUint8List, + this.flutterEchoList, + this.flutterEchoProxyApiList, + this.flutterEchoMap, + this.flutterEchoProxyApiMap, + this.flutterEchoEnum, + this.flutterEchoProxyApi, + this.flutterEchoNullableBool, + this.flutterEchoNullableInt, + this.flutterEchoNullableDouble, + this.flutterEchoNullableString, + this.flutterEchoNullableUint8List, + this.flutterEchoNullableList, + this.flutterEchoNullableMap, + this.flutterEchoNullableEnum, + this.flutterEchoNullableProxyApi, + this.flutterNoopAsync, + this.flutterEchoAsyncString, + }) : super.pigeon_detached() { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecProxyApiTestClass; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.namedConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([ + pigeonVar_instanceIdentifier, + aBool, + anInt, + aDouble, + aString, + aUint8List, + aList, + aMap, + anEnum, + aProxyApi, + aNullableBool, + aNullableInt, + aNullableDouble, + aNullableString, + aNullableUint8List, + aNullableList, + aNullableMap, + aNullableEnum, + aNullableProxyApi + ]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } + /// Constructs [ProxyApiTestClass] without creating the associated native object. /// /// This should only be used by subclasses created by this library or to diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/ProxyApiTestApiImpls.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/ProxyApiTestApiImpls.kt index bfe6e4257e79..b9389fd10dc7 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/ProxyApiTestApiImpls.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/ProxyApiTestApiImpls.kt @@ -74,6 +74,29 @@ class ProxyApiTestClassApi(override val pigeonRegistrar: ProxyApiRegistrar) : return ProxyApiTestClass() } + override fun namedConstructor( + aBool: Boolean, + anInt: Long, + aDouble: Double, + aString: String, + aUint8List: ByteArray, + aList: List, + aMap: Map, + anEnum: ProxyApiTestEnum, + aProxyApi: ProxyApiSuperClass, + aNullableBool: Boolean?, + aNullableInt: Long?, + aNullableDouble: Double?, + aNullableString: String?, + aNullableUint8List: ByteArray?, + aNullableList: List?, + aNullableMap: Map?, + aNullableEnum: ProxyApiTestEnum?, + aNullableProxyApi: ProxyApiSuperClass?, + ): ProxyApiTestClass { + return ProxyApiTestClass() + } + override fun attachedField(pigeon_instance: ProxyApiTestClass): ProxyApiSuperClass { return ProxyApiSuperClass() } diff --git a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/ProxyApiTests.gen.kt b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/ProxyApiTests.gen.kt index 184a5b00f599..08b6b635c27e 100644 --- a/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/ProxyApiTests.gen.kt +++ b/packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/ProxyApiTests.gen.kt @@ -549,6 +549,27 @@ abstract class PigeonApiProxyApiTestClass( nullableProxyApiParam: com.example.test_plugin.ProxyApiSuperClass? ): ProxyApiTestClass + abstract fun namedConstructor( + aBool: Boolean, + anInt: Long, + aDouble: Double, + aString: String, + aUint8List: ByteArray, + aList: List, + aMap: Map, + anEnum: ProxyApiTestEnum, + aProxyApi: com.example.test_plugin.ProxyApiSuperClass, + aNullableBool: Boolean?, + aNullableInt: Long?, + aNullableDouble: Double?, + aNullableString: String?, + aNullableUint8List: ByteArray?, + aNullableList: List?, + aNullableMap: Map?, + aNullableEnum: ProxyApiTestEnum?, + aNullableProxyApi: com.example.test_plugin.ProxyApiSuperClass? + ): ProxyApiTestClass + abstract fun attachedField( pigeon_instance: ProxyApiTestClass ): com.example.test_plugin.ProxyApiSuperClass @@ -1108,6 +1129,67 @@ abstract class PigeonApiProxyApiTestClass( channel.setMessageHandler(null) } } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.namedConstructor", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_identifierArg = args[0] as Long + val aBoolArg = args[1] as Boolean + val anIntArg = args[2] as Long + val aDoubleArg = args[3] as Double + val aStringArg = args[4] as String + val aUint8ListArg = args[5] as ByteArray + val aListArg = args[6] as List + val aMapArg = args[7] as Map + val anEnumArg = args[8] as ProxyApiTestEnum + val aProxyApiArg = args[9] as com.example.test_plugin.ProxyApiSuperClass + val aNullableBoolArg = args[10] as Boolean? + val aNullableIntArg = args[11] as Long? + val aNullableDoubleArg = args[12] as Double? + val aNullableStringArg = args[13] as String? + val aNullableUint8ListArg = args[14] as ByteArray? + val aNullableListArg = args[15] as List? + val aNullableMapArg = args[16] as Map? + val aNullableEnumArg = args[17] as ProxyApiTestEnum? + val aNullableProxyApiArg = args[18] as com.example.test_plugin.ProxyApiSuperClass? + val wrapped: List = + try { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + api.namedConstructor( + aBoolArg, + anIntArg, + aDoubleArg, + aStringArg, + aUint8ListArg, + aListArg, + aMapArg, + anEnumArg, + aProxyApiArg, + aNullableBoolArg, + aNullableIntArg, + aNullableDoubleArg, + aNullableStringArg, + aNullableUint8ListArg, + aNullableListArg, + aNullableMapArg, + aNullableEnumArg, + aNullableProxyApiArg), + pigeon_identifierArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } run { val channel = BasicMessageChannel( diff --git a/packages/pigeon/platform_tests/test_plugin/ios/Classes/ProxyApiTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/ios/Classes/ProxyApiTests.gen.swift index d3a699ca47a9..506565c1dd67 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/ProxyApiTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/ProxyApiTests.gen.swift @@ -628,6 +628,15 @@ protocol PigeonApiDelegateProxyApiTestClass { nullableListParam: [Any?]?, nullableMapParam: [String?: Any?]?, nullableEnumParam: ProxyApiTestEnum?, nullableProxyApiParam: ProxyApiSuperClass? ) throws -> ProxyApiTestClass + func namedConstructor( + pigeonApi: PigeonApiProxyApiTestClass, aBool: Bool, anInt: Int64, aDouble: Double, + aString: String, aUint8List: FlutterStandardTypedData, aList: [Any?], aMap: [String?: Any?], + anEnum: ProxyApiTestEnum, aProxyApi: ProxyApiSuperClass, aNullableBool: Bool?, + aNullableInt: Int64?, aNullableDouble: Double?, aNullableString: String?, + aNullableUint8List: FlutterStandardTypedData?, aNullableList: [Any?]?, + aNullableMap: [String?: Any?]?, aNullableEnum: ProxyApiTestEnum?, + aNullableProxyApi: ProxyApiSuperClass? + ) throws -> ProxyApiTestClass func attachedField(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws -> ProxyApiSuperClass func staticAttachedField(pigeonApi: PigeonApiProxyApiTestClass) throws -> ProxyApiSuperClass @@ -1168,6 +1177,50 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass { } else { pigeonDefaultConstructorChannel.setMessageHandler(nil) } + let namedConstructorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.namedConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + namedConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + let aBoolArg = args[1] as! Bool + let anIntArg = args[2] as! Int64 + let aDoubleArg = args[3] as! Double + let aStringArg = args[4] as! String + let aUint8ListArg = args[5] as! FlutterStandardTypedData + let aListArg = args[6] as! [Any?] + let aMapArg = args[7] as! [String?: Any?] + let anEnumArg = args[8] as! ProxyApiTestEnum + let aProxyApiArg = args[9] as! ProxyApiSuperClass + let aNullableBoolArg: Bool? = nilOrValue(args[10]) + let aNullableIntArg: Int64? = nilOrValue(args[11]) + let aNullableDoubleArg: Double? = nilOrValue(args[12]) + let aNullableStringArg: String? = nilOrValue(args[13]) + let aNullableUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[14]) + let aNullableListArg: [Any?]? = nilOrValue(args[15]) + let aNullableMapArg: [String?: Any?]? = nilOrValue(args[16]) + let aNullableEnumArg: ProxyApiTestEnum? = nilOrValue(args[17]) + let aNullableProxyApiArg: ProxyApiSuperClass? = nilOrValue(args[18]) + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.namedConstructor( + pigeonApi: api, aBool: aBoolArg, anInt: anIntArg, aDouble: aDoubleArg, + aString: aStringArg, aUint8List: aUint8ListArg, aList: aListArg, aMap: aMapArg, + anEnum: anEnumArg, aProxyApi: aProxyApiArg, aNullableBool: aNullableBoolArg, + aNullableInt: aNullableIntArg, aNullableDouble: aNullableDoubleArg, + aNullableString: aNullableStringArg, aNullableUint8List: aNullableUint8ListArg, + aNullableList: aNullableListArg, aNullableMap: aNullableMapArg, + aNullableEnum: aNullableEnumArg, aNullableProxyApi: aNullableProxyApiArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + namedConstructorChannel.setMessageHandler(nil) + } let attachedFieldChannel = FlutterBasicMessageChannel( name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.attachedField", 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 b4238de3be91..4a6902f4d229 100644 --- a/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift @@ -1238,6 +1238,18 @@ class ProxyApiDelegate: ProxyApiTestsPigeonProxyApiDelegate { return ProxyApiTestClass() } + func namedConstructor( + pigeonApi: PigeonApiProxyApiTestClass, aBool: Bool, anInt: Int64, aDouble: Double, + aString: String, aUint8List: FlutterStandardTypedData, aList: [Any?], aMap: [String?: Any?], + anEnum: ProxyApiTestEnum, aProxyApi: ProxyApiSuperClass, aNullableBool: Bool?, + aNullableInt: Int64?, aNullableDouble: Double?, aNullableString: String?, + aNullableUint8List: FlutterStandardTypedData?, aNullableList: [Any?]?, + aNullableMap: [String?: Any?]?, aNullableEnum: ProxyApiTestEnum?, + aNullableProxyApi: ProxyApiSuperClass? + ) throws -> ProxyApiTestClass { + return ProxyApiTestClass() + } + func attachedField(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws -> ProxyApiSuperClass { diff --git a/packages/pigeon/platform_tests/test_plugin/macos/Classes/ProxyApiTests.gen.swift b/packages/pigeon/platform_tests/test_plugin/macos/Classes/ProxyApiTests.gen.swift index d3a699ca47a9..506565c1dd67 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/ProxyApiTests.gen.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/ProxyApiTests.gen.swift @@ -628,6 +628,15 @@ protocol PigeonApiDelegateProxyApiTestClass { nullableListParam: [Any?]?, nullableMapParam: [String?: Any?]?, nullableEnumParam: ProxyApiTestEnum?, nullableProxyApiParam: ProxyApiSuperClass? ) throws -> ProxyApiTestClass + func namedConstructor( + pigeonApi: PigeonApiProxyApiTestClass, aBool: Bool, anInt: Int64, aDouble: Double, + aString: String, aUint8List: FlutterStandardTypedData, aList: [Any?], aMap: [String?: Any?], + anEnum: ProxyApiTestEnum, aProxyApi: ProxyApiSuperClass, aNullableBool: Bool?, + aNullableInt: Int64?, aNullableDouble: Double?, aNullableString: String?, + aNullableUint8List: FlutterStandardTypedData?, aNullableList: [Any?]?, + aNullableMap: [String?: Any?]?, aNullableEnum: ProxyApiTestEnum?, + aNullableProxyApi: ProxyApiSuperClass? + ) throws -> ProxyApiTestClass func attachedField(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws -> ProxyApiSuperClass func staticAttachedField(pigeonApi: PigeonApiProxyApiTestClass) throws -> ProxyApiSuperClass @@ -1168,6 +1177,50 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass { } else { pigeonDefaultConstructorChannel.setMessageHandler(nil) } + let namedConstructorChannel = FlutterBasicMessageChannel( + name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.namedConstructor", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + namedConstructorChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonIdentifierArg = args[0] as! Int64 + let aBoolArg = args[1] as! Bool + let anIntArg = args[2] as! Int64 + let aDoubleArg = args[3] as! Double + let aStringArg = args[4] as! String + let aUint8ListArg = args[5] as! FlutterStandardTypedData + let aListArg = args[6] as! [Any?] + let aMapArg = args[7] as! [String?: Any?] + let anEnumArg = args[8] as! ProxyApiTestEnum + let aProxyApiArg = args[9] as! ProxyApiSuperClass + let aNullableBoolArg: Bool? = nilOrValue(args[10]) + let aNullableIntArg: Int64? = nilOrValue(args[11]) + let aNullableDoubleArg: Double? = nilOrValue(args[12]) + let aNullableStringArg: String? = nilOrValue(args[13]) + let aNullableUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[14]) + let aNullableListArg: [Any?]? = nilOrValue(args[15]) + let aNullableMapArg: [String?: Any?]? = nilOrValue(args[16]) + let aNullableEnumArg: ProxyApiTestEnum? = nilOrValue(args[17]) + let aNullableProxyApiArg: ProxyApiSuperClass? = nilOrValue(args[18]) + do { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + try api.pigeonDelegate.namedConstructor( + pigeonApi: api, aBool: aBoolArg, anInt: anIntArg, aDouble: aDoubleArg, + aString: aStringArg, aUint8List: aUint8ListArg, aList: aListArg, aMap: aMapArg, + anEnum: anEnumArg, aProxyApi: aProxyApiArg, aNullableBool: aNullableBoolArg, + aNullableInt: aNullableIntArg, aNullableDouble: aNullableDoubleArg, + aNullableString: aNullableStringArg, aNullableUint8List: aNullableUint8ListArg, + aNullableList: aNullableListArg, aNullableMap: aNullableMapArg, + aNullableEnum: aNullableEnumArg, aNullableProxyApi: aNullableProxyApiArg), + withIdentifier: pigeonIdentifierArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + namedConstructorChannel.setMessageHandler(nil) + } let attachedFieldChannel = FlutterBasicMessageChannel( name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.attachedField", 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 fb5c21dabf18..5128c17334c4 100644 --- a/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift +++ b/packages/pigeon/platform_tests/test_plugin/macos/Classes/TestPlugin.swift @@ -1237,6 +1237,18 @@ class ProxyApiDelegate: ProxyApiTestsPigeonProxyApiDelegate { return ProxyApiTestClass() } + func namedConstructor( + pigeonApi: PigeonApiProxyApiTestClass, aBool: Bool, anInt: Int64, aDouble: Double, + aString: String, aUint8List: FlutterStandardTypedData, aList: [Any?], aMap: [String?: Any?], + anEnum: ProxyApiTestEnum, aProxyApi: ProxyApiSuperClass, aNullableBool: Bool?, + aNullableInt: Int64?, aNullableDouble: Double?, aNullableString: String?, + aNullableUint8List: FlutterStandardTypedData?, aNullableList: [Any?]?, + aNullableMap: [String?: Any?]?, aNullableEnum: ProxyApiTestEnum?, + aNullableProxyApi: ProxyApiSuperClass? + ) throws -> ProxyApiTestClass { + return ProxyApiTestClass() + } + func attachedField(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass) throws -> ProxyApiSuperClass { diff --git a/packages/pigeon/pubspec.yaml b/packages/pigeon/pubspec.yaml index 192770b714d9..c3633734b54d 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%3A%22p%3A+pigeon%22 -version: 22.6.3 # This must match the version in lib/generator_tools.dart +version: 22.6.4 # This must match the version in lib/generator_tools.dart environment: sdk: ^3.3.0 diff --git a/packages/pigeon/test/swift/proxy_api_test.dart b/packages/pigeon/test/swift/proxy_api_test.dart index 18df858f81e9..3c9cb12c7562 100644 --- a/packages/pigeon/test/swift/proxy_api_test.dart +++ b/packages/pigeon/test/swift/proxy_api_test.dart @@ -355,6 +355,43 @@ void main() { ); }); + test('named constructor', () { + final Root root = Root( + apis: [ + AstProxyApi(name: 'Api', constructors: [ + Constructor( + name: 'myConstructorName', + parameters: [], + ) + ], fields: [], methods: []), + ], + classes: [], + enums: [], + ); + final StringBuffer sink = StringBuffer(); + const SwiftGenerator generator = SwiftGenerator(); + generator.generate( + const SwiftOptions(), + root, + sink, + dartPackageName: DEFAULT_PACKAGE_NAME, + ); + final String code = sink.toString(); + final String collapsedCode = _collapseNewlineAndIndentation(code); + expect( + collapsedCode, + contains( + 'func myConstructorName(pigeonApi: PigeonApiApi) throws -> Api', + ), + ); + expect( + collapsedCode, + contains( + r'let myConstructorNameChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.test_package.Api.myConstructorName", binaryMessenger: binaryMessenger, codec: codec)', + ), + ); + }); + test('multiple params constructor', () { final Enum anEnum = Enum( name: 'AnEnum', diff --git a/packages/pigeon/tool/shared/generation.dart b/packages/pigeon/tool/shared/generation.dart index 4cee0d4de568..9416eb788d94 100644 --- a/packages/pigeon/tool/shared/generation.dart +++ b/packages/pigeon/tool/shared/generation.dart @@ -118,7 +118,7 @@ Future generateTestPigeons( ? null : '$outputBase/ios/Classes/$pascalCaseName.gen.swift', swiftErrorClassName: swiftErrorClassName, - swiftIncludeErrorClass: input != 'core_tests', + swiftIncludeErrorClass: input != 'background_platform_channels', // Linux gobjectHeaderOut: skipLanguages.contains(GeneratorLanguage.gobject) ? null @@ -150,7 +150,7 @@ Future generateTestPigeons( ? null : '$outputBase/macos/Classes/$pascalCaseName.gen.swift', swiftErrorClassName: swiftErrorClassName, - swiftIncludeErrorClass: input != 'core_tests', + swiftIncludeErrorClass: input != 'background_platform_channels', suppressVersion: true, dartPackageName: 'pigeon_integration_tests', injectOverflowTypes: includeOverflow && input == 'core_tests',