Skip to content

Commit e362bb9

Browse files
authored
[pigeon] update nullish checks to use new isNullish method (flutter#12985)
follow up to flutter/packages#12531 just to keep code cleaner (while it's on top of my mind)
1 parent 92e7ec3 commit e362bb9

8 files changed

Lines changed: 59 additions & 53 deletions

File tree

‎packages/pigeon/CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 29.0.3
22

3+
* [swift] Uses `isNullish` to check for null and `NSNull` in non-null Flutter API returns.
34
* Updates minimum supported SDK version to Flutter 3.41/Dart 3.11.
45

56
## 29.0.2

‎packages/pigeon/example/app/ios/Runner/Messages.g.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class MessageFlutterApi: MessageFlutterApiProtocol {
401401
let message: String? = nilOrValue(listResponse[1])
402402
let details: String? = nilOrValue(listResponse[2])
403403
continuation.resume(throwing: PigeonError(code: code, message: message, details: details))
404-
} else if listResponse[0] == nil || listResponse[0] is NSNull {
404+
} else if MessagesPigeonInternal.isNullish(listResponse[0]) {
405405
continuation.resume(
406406
throwing: PigeonError(
407407
code: "null-error",

‎packages/pigeon/lib/src/generator_tools.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'generator.dart';
1616
/// The current version of pigeon.
1717
///
1818
/// This must match the version in pubspec.yaml.
19-
const String pigeonVersion = '29.0.2';
19+
const String pigeonVersion = '29.0.3';
2020

2121
/// Default plugin package name.
2222
const String defaultPluginPackageName = 'dev.flutter.pigeon';

‎packages/pigeon/lib/src/swift/swift_generator.dart‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,13 +2682,18 @@ enum ${_classNamePrefix}PigeonInternalNumberType: Int {
26822682
);
26832683
}, addTrailingNewline: false);
26842684
if (!returnType.isNullable && !returnType.isVoid) {
2685-
indent.addScoped('else if listResponse[0] == nil || listResponse[0] is NSNull {', '} ', () {
2686-
indent.writeln(
2687-
resumeError(
2688-
'${_getErrorClassName(generatorOptions)}(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: "")',
2689-
),
2690-
);
2691-
}, addTrailingNewline: false);
2685+
indent.addScoped(
2686+
'else if ${_classNamePrefix}PigeonInternal.isNullish(listResponse[0]) {',
2687+
'} ',
2688+
() {
2689+
indent.writeln(
2690+
resumeError(
2691+
'${_getErrorClassName(generatorOptions)}(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: "")',
2692+
),
2693+
);
2694+
},
2695+
addTrailingNewline: false,
2696+
);
26922697
}
26932698
indent.addScoped('else {', '}', () {
26942699
if (returnType.isVoid) {

‎packages/pigeon/platform_tests/test_plugin/darwin/test_plugin/Sources/test_plugin/CoreTests.gen.swift‎

Lines changed: 29 additions & 29 deletions
Large diffs are not rendered by default.

‎packages/pigeon/platform_tests/test_plugin/darwin/test_plugin/Sources/test_plugin/ProxyApiTests.gen.swift‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,7 +3019,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
30193019
let message: String? = nilOrValue(listResponse[1])
30203020
let details: String? = nilOrValue(listResponse[2])
30213021
completion(.failure(ProxyApiTestsError(code: code, message: message, details: details)))
3022-
} else if listResponse[0] == nil || listResponse[0] is NSNull {
3022+
} else if ProxyApiTestsPigeonInternal.isNullish(listResponse[0]) {
30233023
completion(
30243024
.failure(
30253025
ProxyApiTestsError(
@@ -3070,7 +3070,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
30703070
let message: String? = nilOrValue(listResponse[1])
30713071
let details: String? = nilOrValue(listResponse[2])
30723072
completion(.failure(ProxyApiTestsError(code: code, message: message, details: details)))
3073-
} else if listResponse[0] == nil || listResponse[0] is NSNull {
3073+
} else if ProxyApiTestsPigeonInternal.isNullish(listResponse[0]) {
30743074
completion(
30753075
.failure(
30763076
ProxyApiTestsError(
@@ -3121,7 +3121,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
31213121
let message: String? = nilOrValue(listResponse[1])
31223122
let details: String? = nilOrValue(listResponse[2])
31233123
completion(.failure(ProxyApiTestsError(code: code, message: message, details: details)))
3124-
} else if listResponse[0] == nil || listResponse[0] is NSNull {
3124+
} else if ProxyApiTestsPigeonInternal.isNullish(listResponse[0]) {
31253125
completion(
31263126
.failure(
31273127
ProxyApiTestsError(
@@ -3172,7 +3172,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
31723172
let message: String? = nilOrValue(listResponse[1])
31733173
let details: String? = nilOrValue(listResponse[2])
31743174
completion(.failure(ProxyApiTestsError(code: code, message: message, details: details)))
3175-
} else if listResponse[0] == nil || listResponse[0] is NSNull {
3175+
} else if ProxyApiTestsPigeonInternal.isNullish(listResponse[0]) {
31763176
completion(
31773177
.failure(
31783178
ProxyApiTestsError(
@@ -3223,7 +3223,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
32233223
let message: String? = nilOrValue(listResponse[1])
32243224
let details: String? = nilOrValue(listResponse[2])
32253225
completion(.failure(ProxyApiTestsError(code: code, message: message, details: details)))
3226-
} else if listResponse[0] == nil || listResponse[0] is NSNull {
3226+
} else if ProxyApiTestsPigeonInternal.isNullish(listResponse[0]) {
32273227
completion(
32283228
.failure(
32293229
ProxyApiTestsError(
@@ -3274,7 +3274,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
32743274
let message: String? = nilOrValue(listResponse[1])
32753275
let details: String? = nilOrValue(listResponse[2])
32763276
completion(.failure(ProxyApiTestsError(code: code, message: message, details: details)))
3277-
} else if listResponse[0] == nil || listResponse[0] is NSNull {
3277+
} else if ProxyApiTestsPigeonInternal.isNullish(listResponse[0]) {
32783278
completion(
32793279
.failure(
32803280
ProxyApiTestsError(
@@ -3326,7 +3326,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
33263326
let message: String? = nilOrValue(listResponse[1])
33273327
let details: String? = nilOrValue(listResponse[2])
33283328
completion(.failure(ProxyApiTestsError(code: code, message: message, details: details)))
3329-
} else if listResponse[0] == nil || listResponse[0] is NSNull {
3329+
} else if ProxyApiTestsPigeonInternal.isNullish(listResponse[0]) {
33303330
completion(
33313331
.failure(
33323332
ProxyApiTestsError(
@@ -3377,7 +3377,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
33773377
let message: String? = nilOrValue(listResponse[1])
33783378
let details: String? = nilOrValue(listResponse[2])
33793379
completion(.failure(ProxyApiTestsError(code: code, message: message, details: details)))
3380-
} else if listResponse[0] == nil || listResponse[0] is NSNull {
3380+
} else if ProxyApiTestsPigeonInternal.isNullish(listResponse[0]) {
33813381
completion(
33823382
.failure(
33833383
ProxyApiTestsError(
@@ -3430,7 +3430,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
34303430
let message: String? = nilOrValue(listResponse[1])
34313431
let details: String? = nilOrValue(listResponse[2])
34323432
completion(.failure(ProxyApiTestsError(code: code, message: message, details: details)))
3433-
} else if listResponse[0] == nil || listResponse[0] is NSNull {
3433+
} else if ProxyApiTestsPigeonInternal.isNullish(listResponse[0]) {
34343434
completion(
34353435
.failure(
34363436
ProxyApiTestsError(
@@ -3481,7 +3481,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
34813481
let message: String? = nilOrValue(listResponse[1])
34823482
let details: String? = nilOrValue(listResponse[2])
34833483
completion(.failure(ProxyApiTestsError(code: code, message: message, details: details)))
3484-
} else if listResponse[0] == nil || listResponse[0] is NSNull {
3484+
} else if ProxyApiTestsPigeonInternal.isNullish(listResponse[0]) {
34853485
completion(
34863486
.failure(
34873487
ProxyApiTestsError(
@@ -3532,7 +3532,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
35323532
let message: String? = nilOrValue(listResponse[1])
35333533
let details: String? = nilOrValue(listResponse[2])
35343534
completion(.failure(ProxyApiTestsError(code: code, message: message, details: details)))
3535-
} else if listResponse[0] == nil || listResponse[0] is NSNull {
3535+
} else if ProxyApiTestsPigeonInternal.isNullish(listResponse[0]) {
35363536
completion(
35373537
.failure(
35383538
ProxyApiTestsError(
@@ -4034,7 +4034,7 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
40344034
let message: String? = nilOrValue(listResponse[1])
40354035
let details: String? = nilOrValue(listResponse[2])
40364036
completion(.failure(ProxyApiTestsError(code: code, message: message, details: details)))
4037-
} else if listResponse[0] == nil || listResponse[0] is NSNull {
4037+
} else if ProxyApiTestsPigeonInternal.isNullish(listResponse[0]) {
40384038
completion(
40394039
.failure(
40404040
ProxyApiTestsError(

‎packages/pigeon/pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: pigeon
22
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
33
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pigeon%22
5-
version: 29.0.2 # This must match the version in lib/src/generator_tools.dart
5+
version: 29.0.3 # This must match the version in lib/src/generator_tools.dart
66

77
environment:
88
sdk: ^3.11.0

‎packages/pigeon/test/swift_generator_test.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ void main() {
12201220
const generator = SwiftGenerator();
12211221
generator.generate(swiftOptions, root, sink, dartPackageName: DEFAULT_PACKAGE_NAME);
12221222
final code = sink.toString();
1223-
expect(code, contains('else if listResponse[0] == nil || listResponse[0] is NSNull {'));
1223+
expect(code, contains('else if PigeonInternal.isNullish(listResponse[0]) {'));
12241224
});
12251225

12261226
test('return nullable host', () {

0 commit comments

Comments
 (0)