@@ -949,6 +949,9 @@ if (wrapped == nil) {
949
949
let identifier = self.readValue()
950
950
let instance: AnyObject? = pigeonRegistrar.instanceManager.instance(
951
951
forIdentifier: identifier is Int64 ? identifier as! Int64 : Int64(identifier as! Int32))
952
+ if instance == nil {
953
+ print("Failed to find instance with identifier: \\ (identifier!)")
954
+ }
952
955
return instance
953
956
default:
954
957
return super.readValue(ofType: type)
@@ -1502,7 +1505,7 @@ private func nilOrValue<T>(_ value: Any?) -> T? {
1502
1505
}
1503
1506
indent.addScoped ('else {' , '}' , () {
1504
1507
if (returnType.isVoid) {
1505
- indent.writeln ('completion(.success(Void ()))' );
1508
+ indent.writeln ('completion(.success(()))' );
1506
1509
} else {
1507
1510
final String fieldType = _swiftTypeForDartType (returnType);
1508
1511
_writeGenericCasting (
@@ -2318,63 +2321,70 @@ private func nilOrValue<T>(_ value: Any?) -> T? {
2318
2321
.failure(
2319
2322
${_getErrorClassName (generatorOptions )}(
2320
2323
code: "ignore-calls-error",
2321
- message: "Calls to Dart are being ignored.", details: "")))
2322
- return''' ,
2324
+ message: "Calls to Dart are being ignored.", details: "")))''' ,
2323
2325
);
2324
2326
},
2327
+ addTrailingNewline: false ,
2325
2328
);
2326
2329
2327
2330
indent.writeScoped (
2328
- 'if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) {' ,
2331
+ ' else if pigeonRegistrar.instanceManager.containsInstance(pigeonInstance as AnyObject) {' ,
2329
2332
'}' ,
2330
2333
() {
2331
- indent.writeln ('completion(.success(Void()))' );
2332
- indent.writeln ('return' );
2334
+ indent.writeln ('completion(.success(()))' );
2333
2335
},
2336
+ addTrailingNewline: false ,
2334
2337
);
2335
- if (api.hasCallbackConstructor ()) {
2336
- indent.writeln (
2337
- 'let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeonInstance as AnyObject)' ,
2338
- );
2339
- enumerate (api.unattachedFields, (int index, ApiField field) {
2340
- final String argName = _getSafeArgumentName (index, field);
2338
+ indent.writeScoped (' else {' , '}' , () {
2339
+ if (api.hasCallbackConstructor ()) {
2341
2340
indent.writeln (
2342
- 'let $ argName = try! pigeonDelegate.${ field . name }(pigeonApi: self, pigeonInstance: pigeonInstance )' ,
2341
+ 'let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( pigeonInstance as AnyObject )' ,
2343
2342
);
2344
- });
2345
- indent.writeln (
2346
- 'let binaryMessenger = pigeonRegistrar.binaryMessenger' ,
2347
- );
2348
- indent.writeln ('let codec = pigeonRegistrar.codec' );
2349
- _writeFlutterMethodMessageCall (
2350
- indent,
2351
- generatorOptions: generatorOptions,
2352
- parameters: < Parameter > [
2353
- Parameter (
2354
- name: 'pigeonIdentifier' ,
2355
- type: const TypeDeclaration (
2356
- baseName: 'int' ,
2357
- isNullable: false ,
2343
+ enumerate (api.unattachedFields, (int index, ApiField field) {
2344
+ final String argName = _getSafeArgumentName (index, field);
2345
+ indent.writeln (
2346
+ 'let $argName = try! pigeonDelegate.${field .name }(pigeonApi: self, pigeonInstance: pigeonInstance)' ,
2347
+ );
2348
+ });
2349
+ indent.writeln (
2350
+ 'let binaryMessenger = pigeonRegistrar.binaryMessenger' ,
2351
+ );
2352
+ indent.writeln ('let codec = pigeonRegistrar.codec' );
2353
+ _writeFlutterMethodMessageCall (
2354
+ indent,
2355
+ generatorOptions: generatorOptions,
2356
+ parameters: < Parameter > [
2357
+ Parameter (
2358
+ name: 'pigeonIdentifier' ,
2359
+ type: const TypeDeclaration (
2360
+ baseName: 'int' ,
2361
+ isNullable: false ,
2362
+ ),
2358
2363
),
2364
+ ...api.unattachedFields.map (
2365
+ (ApiField field) {
2366
+ return Parameter (name: field.name, type: field.type);
2367
+ },
2368
+ ),
2369
+ ],
2370
+ returnType: const TypeDeclaration .voidDeclaration (),
2371
+ channelName: makeChannelNameWithStrings (
2372
+ apiName: api.name,
2373
+ methodName: newInstanceMethodName,
2374
+ dartPackageName: dartPackageName,
2359
2375
),
2360
- ...api.unattachedFields.map (
2361
- (ApiField field) {
2362
- return Parameter (name: field.name, type: field.type);
2363
- },
2364
- ),
2365
- ],
2366
- returnType: const TypeDeclaration .voidDeclaration (),
2367
- channelName: makeChannelNameWithStrings (
2368
- apiName: api.name,
2369
- methodName: newInstanceMethodName,
2370
- dartPackageName: dartPackageName,
2371
- ),
2372
- );
2373
- } else {
2374
- indent.writeln (
2375
- 'print("Error: Attempting to create a new Dart instance of ${api .name }, but the class has a nonnull callback method.")' ,
2376
- );
2377
- }
2376
+ );
2377
+ } else {
2378
+ indent.format (
2379
+ '''
2380
+ completion(
2381
+ .failure(
2382
+ ${_getErrorClassName (generatorOptions )}(
2383
+ code: "new-instance-error",
2384
+ message: "Error: Attempting to create a new Dart instance of ${api .name }, but the class has a nonnull callback method.", details: "")))''' ,
2385
+ );
2386
+ }
2387
+ });
2378
2388
});
2379
2389
2380
2390
if (unsupportedPlatforms != null ) {
0 commit comments