Skip to content

Commit 574ee0b

Browse files
committed
crash fix
1 parent 45323d3 commit 574ee0b

File tree

24 files changed

+185
-148
lines changed

24 files changed

+185
-148
lines changed

packages/pigeon/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 9.1.2
2+
3+
* [swift] Fixes NSNull casting crash.
4+
15
## 9.1.1
26

37
* [swift] Removes experimental tags.

packages/pigeon/lib/generator_tools.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'ast.dart';
1111
/// The current version of pigeon.
1212
///
1313
/// This must match the version in pubspec.yaml.
14-
const String pigeonVersion = '9.1.1';
14+
const String pigeonVersion = '9.1.2';
1515

1616
/// Read all the content from [stdin] to a String.
1717
String readStdin() {

packages/pigeon/lib/swift_generator.dart

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ import FlutterMacOS
199199
'${field.name} = $fieldType(rawValue: ${field.name}RawValue)');
200200
});
201201
} else {
202-
indent.writeln('let ${field.name} = $listValue as! $fieldType? ');
202+
indent.writeln(
203+
'let ${field.name} = ${_castForceUnwrap(listValue, field.type, root)} ');
203204
}
204205
} else {
205206
if (!hostDatatype.isBuiltin &&
@@ -637,11 +638,25 @@ import FlutterMacOS
637638
});
638639
}
639640

641+
void _writeNSNullToNil(Indent indent) {
642+
indent.format('''
643+
644+
private func nullToNil(value : Any?) -> Any? {
645+
if value is NSNull {
646+
return nil
647+
} else {
648+
return value
649+
}
650+
}
651+
''');
652+
}
653+
640654
@override
641655
void writeGeneralUtilities(
642656
SwiftOptions generatorOptions, Root root, Indent indent) {
643657
_writeWrapResult(indent);
644658
_writeWrapError(indent);
659+
_writeNSNullToNil(indent);
645660
}
646661
}
647662

@@ -677,8 +692,8 @@ String _castForceUnwrap(String value, TypeDeclaration type, Root root) {
677692
} else if (type.baseName == 'Object') {
678693
// Special-cased to avoid warnings about using 'as' with Any.
679694
return value;
680-
} else if (type.baseName == 'int') {
681-
return '($value is Int) ? Int64($value as! Int) : $value as! Int64$castUnwrap';
695+
} else if (type.isNullable) {
696+
return '($value is NSNull) ? nullToNil(value: $value) as! ${_swiftTypeForDartType(type)}$castUnwrap : $value as! ${_swiftTypeForDartType(type)}$castUnwrap';
682697
} else {
683698
return '$value as! ${_swiftTypeForDartType(type)}$castUnwrap';
684699
}

packages/pigeon/mock_handler_tester/test/message.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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
88

packages/pigeon/mock_handler_tester/test/test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import
88
// ignore_for_file: avoid_relative_lib_imports

packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/CoreTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
package com.example.alternate_language_test_plugin;

packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
#import <Foundation/Foundation.h>

packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/CoreTests.gen.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
#import "CoreTests.gen.h"

packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/core_tests.gen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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
88

packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/flutter_unittests.gen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
//
5-
// Autogenerated from Pigeon (v9.1.1), do not edit directly.
5+
// Autogenerated from Pigeon (v9.1.2), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77
// 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
88

0 commit comments

Comments
 (0)