Skip to content

Commit 8fdc7b5

Browse files
authored
[pigeon] Fixes swift int64 support for Swift (#3455)
[pigeon] Fixes swift int64 support for Swift
1 parent 720fd72 commit 8fdc7b5

File tree

31 files changed

+540
-313
lines changed

31 files changed

+540
-313
lines changed

packages/pigeon/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 9.0.7
2+
3+
* [swift] Changes all ints to int64.
4+
May require code updates to existing code.
5+
* Adds integration tests for int64.
6+
17
## 9.0.6
28

39
* [kotlin] Removes safe casting from decode process.

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.0.6';
14+
const String pigeonVersion = '9.0.7';
1515

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

packages/pigeon/lib/swift_generator.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,15 +669,17 @@ String _camelCase(String text) {
669669

670670
String _castForceUnwrap(String value, TypeDeclaration type, Root root) {
671671
final String forceUnwrap = type.isNullable ? '' : '!';
672+
final String castUnwrap = type.isNullable ? '?' : '';
672673
if (isEnum(root, type)) {
673674
final String nullableConditionPrefix =
674675
type.isNullable ? '$value == nil ? nil : ' : '';
675676
return '$nullableConditionPrefix${_swiftTypeForDartType(type)}(rawValue: $value as! Int)$forceUnwrap';
676677
} else if (type.baseName == 'Object') {
677678
// Special-cased to avoid warnings about using 'as' with Any.
678679
return value;
680+
} else if (type.baseName == 'int') {
681+
return '($value is Int) ? Int64($value as! Int) : $value as! Int64$castUnwrap';
679682
} else {
680-
final String castUnwrap = type.isNullable ? '?' : '';
681683
return '$value as! ${_swiftTypeForDartType(type)}$castUnwrap';
682684
}
683685
}
@@ -713,7 +715,7 @@ String? _swiftTypeForBuiltinDartType(TypeDeclaration type) {
713715
'void': 'Void',
714716
'bool': 'Bool',
715717
'String': 'String',
716-
'int': 'Int32',
718+
'int': 'Int64',
717719
'double': 'Double',
718720
'Uint8List': 'FlutterStandardTypedData',
719721
'Int32List': 'FlutterStandardTypedData',

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.0.6), do not edit directly.
5+
// Autogenerated from Pigeon (v9.0.7), 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.0.6), do not edit directly.
5+
// Autogenerated from Pigeon (v9.0.7), 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/pigeons/core_tests.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class AllTypes {
1515
AllTypes({
1616
this.aBool = false,
1717
this.anInt = 0,
18+
this.anInt64 = 0,
1819
this.aDouble = 0,
1920
required this.aByteArray,
2021
required this.a4ByteArray,
@@ -28,6 +29,7 @@ class AllTypes {
2829

2930
bool aBool;
3031
int anInt;
32+
int anInt64;
3133
double aDouble;
3234
Uint8List aByteArray;
3335
Int32List a4ByteArray;
@@ -46,6 +48,7 @@ class AllNullableTypes {
4648
AllNullableTypes(
4749
this.aNullableBool,
4850
this.aNullableInt,
51+
this.aNullableInt64,
4952
this.aNullableDouble,
5053
this.aNullableByteArray,
5154
this.aNullable4ByteArray,
@@ -62,6 +65,7 @@ class AllNullableTypes {
6265

6366
bool? aNullableBool;
6467
int? aNullableInt;
68+
int? aNullableInt64;
6569
double? aNullableDouble;
6670
Uint8List? aNullableByteArray;
6771
Int32List? aNullable4ByteArray;

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

Lines changed: 77 additions & 24 deletions
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.0.6), do not edit directly.
5+
// Autogenerated from Pigeon (v9.0.7), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
package com.example.alternate_language_test_plugin;
@@ -75,6 +75,19 @@ public void setAnInt(@NonNull Long setterArg) {
7575
this.anInt = setterArg;
7676
}
7777

78+
private @NonNull Long anInt64;
79+
80+
public @NonNull Long getAnInt64() {
81+
return anInt64;
82+
}
83+
84+
public void setAnInt64(@NonNull Long setterArg) {
85+
if (setterArg == null) {
86+
throw new IllegalStateException("Nonnull field \"anInt64\" is null.");
87+
}
88+
this.anInt64 = setterArg;
89+
}
90+
7891
private @NonNull Double aDouble;
7992

8093
public @NonNull Double getADouble() {
@@ -211,6 +224,13 @@ public static final class Builder {
211224
return this;
212225
}
213226

227+
private @Nullable Long anInt64;
228+
229+
public @NonNull Builder setAnInt64(@NonNull Long setterArg) {
230+
this.anInt64 = setterArg;
231+
return this;
232+
}
233+
214234
private @Nullable Double aDouble;
215235

216236
public @NonNull Builder setADouble(@NonNull Double setterArg) {
@@ -278,6 +298,7 @@ public static final class Builder {
278298
AllTypes pigeonReturn = new AllTypes();
279299
pigeonReturn.setABool(aBool);
280300
pigeonReturn.setAnInt(anInt);
301+
pigeonReturn.setAnInt64(anInt64);
281302
pigeonReturn.setADouble(aDouble);
282303
pigeonReturn.setAByteArray(aByteArray);
283304
pigeonReturn.setA4ByteArray(a4ByteArray);
@@ -293,9 +314,10 @@ public static final class Builder {
293314

294315
@NonNull
295316
ArrayList<Object> toList() {
296-
ArrayList<Object> toListResult = new ArrayList<Object>(11);
317+
ArrayList<Object> toListResult = new ArrayList<Object>(12);
297318
toListResult.add(aBool);
298319
toListResult.add(anInt);
320+
toListResult.add(anInt64);
299321
toListResult.add(aDouble);
300322
toListResult.add(aByteArray);
301323
toListResult.add(a4ByteArray);
@@ -315,23 +337,28 @@ ArrayList<Object> toList() {
315337
Object anInt = list.get(1);
316338
pigeonResult.setAnInt(
317339
(anInt == null) ? null : ((anInt instanceof Integer) ? (Integer) anInt : (Long) anInt));
318-
Object aDouble = list.get(2);
340+
Object anInt64 = list.get(2);
341+
pigeonResult.setAnInt64(
342+
(anInt64 == null)
343+
? null
344+
: ((anInt64 instanceof Integer) ? (Integer) anInt64 : (Long) anInt64));
345+
Object aDouble = list.get(3);
319346
pigeonResult.setADouble((Double) aDouble);
320-
Object aByteArray = list.get(3);
347+
Object aByteArray = list.get(4);
321348
pigeonResult.setAByteArray((byte[]) aByteArray);
322-
Object a4ByteArray = list.get(4);
349+
Object a4ByteArray = list.get(5);
323350
pigeonResult.setA4ByteArray((int[]) a4ByteArray);
324-
Object a8ByteArray = list.get(5);
351+
Object a8ByteArray = list.get(6);
325352
pigeonResult.setA8ByteArray((long[]) a8ByteArray);
326-
Object aFloatArray = list.get(6);
353+
Object aFloatArray = list.get(7);
327354
pigeonResult.setAFloatArray((double[]) aFloatArray);
328-
Object aList = list.get(7);
355+
Object aList = list.get(8);
329356
pigeonResult.setAList((List<Object>) aList);
330-
Object aMap = list.get(8);
357+
Object aMap = list.get(9);
331358
pigeonResult.setAMap((Map<Object, Object>) aMap);
332-
Object anEnum = list.get(9);
359+
Object anEnum = list.get(10);
333360
pigeonResult.setAnEnum(anEnum == null ? null : AnEnum.values()[(int) anEnum]);
334-
Object aString = list.get(10);
361+
Object aString = list.get(11);
335362
pigeonResult.setAString((String) aString);
336363
return pigeonResult;
337364
}
@@ -359,6 +386,16 @@ public void setANullableInt(@Nullable Long setterArg) {
359386
this.aNullableInt = setterArg;
360387
}
361388

389+
private @Nullable Long aNullableInt64;
390+
391+
public @Nullable Long getANullableInt64() {
392+
return aNullableInt64;
393+
}
394+
395+
public void setANullableInt64(@Nullable Long setterArg) {
396+
this.aNullableInt64 = setterArg;
397+
}
398+
362399
private @Nullable Double aNullableDouble;
363400

364401
public @Nullable Double getANullableDouble() {
@@ -495,6 +532,13 @@ public static final class Builder {
495532
return this;
496533
}
497534

535+
private @Nullable Long aNullableInt64;
536+
537+
public @NonNull Builder setANullableInt64(@Nullable Long setterArg) {
538+
this.aNullableInt64 = setterArg;
539+
return this;
540+
}
541+
498542
private @Nullable Double aNullableDouble;
499543

500544
public @NonNull Builder setANullableDouble(@Nullable Double setterArg) {
@@ -584,6 +628,7 @@ public static final class Builder {
584628
AllNullableTypes pigeonReturn = new AllNullableTypes();
585629
pigeonReturn.setANullableBool(aNullableBool);
586630
pigeonReturn.setANullableInt(aNullableInt);
631+
pigeonReturn.setANullableInt64(aNullableInt64);
587632
pigeonReturn.setANullableDouble(aNullableDouble);
588633
pigeonReturn.setANullableByteArray(aNullableByteArray);
589634
pigeonReturn.setANullable4ByteArray(aNullable4ByteArray);
@@ -602,9 +647,10 @@ public static final class Builder {
602647

603648
@NonNull
604649
ArrayList<Object> toList() {
605-
ArrayList<Object> toListResult = new ArrayList<Object>(14);
650+
ArrayList<Object> toListResult = new ArrayList<Object>(15);
606651
toListResult.add(aNullableBool);
607652
toListResult.add(aNullableInt);
653+
toListResult.add(aNullableInt64);
608654
toListResult.add(aNullableDouble);
609655
toListResult.add(aNullableByteArray);
610656
toListResult.add(aNullable4ByteArray);
@@ -629,30 +675,37 @@ ArrayList<Object> toList() {
629675
(aNullableInt == null)
630676
? null
631677
: ((aNullableInt instanceof Integer) ? (Integer) aNullableInt : (Long) aNullableInt));
632-
Object aNullableDouble = list.get(2);
678+
Object aNullableInt64 = list.get(2);
679+
pigeonResult.setANullableInt64(
680+
(aNullableInt64 == null)
681+
? null
682+
: ((aNullableInt64 instanceof Integer)
683+
? (Integer) aNullableInt64
684+
: (Long) aNullableInt64));
685+
Object aNullableDouble = list.get(3);
633686
pigeonResult.setANullableDouble((Double) aNullableDouble);
634-
Object aNullableByteArray = list.get(3);
687+
Object aNullableByteArray = list.get(4);
635688
pigeonResult.setANullableByteArray((byte[]) aNullableByteArray);
636-
Object aNullable4ByteArray = list.get(4);
689+
Object aNullable4ByteArray = list.get(5);
637690
pigeonResult.setANullable4ByteArray((int[]) aNullable4ByteArray);
638-
Object aNullable8ByteArray = list.get(5);
691+
Object aNullable8ByteArray = list.get(6);
639692
pigeonResult.setANullable8ByteArray((long[]) aNullable8ByteArray);
640-
Object aNullableFloatArray = list.get(6);
693+
Object aNullableFloatArray = list.get(7);
641694
pigeonResult.setANullableFloatArray((double[]) aNullableFloatArray);
642-
Object aNullableList = list.get(7);
695+
Object aNullableList = list.get(8);
643696
pigeonResult.setANullableList((List<Object>) aNullableList);
644-
Object aNullableMap = list.get(8);
697+
Object aNullableMap = list.get(9);
645698
pigeonResult.setANullableMap((Map<Object, Object>) aNullableMap);
646-
Object nullableNestedList = list.get(9);
699+
Object nullableNestedList = list.get(10);
647700
pigeonResult.setNullableNestedList((List<List<Boolean>>) nullableNestedList);
648-
Object nullableMapWithAnnotations = list.get(10);
701+
Object nullableMapWithAnnotations = list.get(11);
649702
pigeonResult.setNullableMapWithAnnotations((Map<String, String>) nullableMapWithAnnotations);
650-
Object nullableMapWithObject = list.get(11);
703+
Object nullableMapWithObject = list.get(12);
651704
pigeonResult.setNullableMapWithObject((Map<String, Object>) nullableMapWithObject);
652-
Object aNullableEnum = list.get(12);
705+
Object aNullableEnum = list.get(13);
653706
pigeonResult.setANullableEnum(
654707
aNullableEnum == null ? null : AnEnum.values()[(int) aNullableEnum]);
655-
Object aNullableString = list.get(13);
708+
Object aNullableString = list.get(14);
656709
pigeonResult.setANullableString((String) aNullableString);
657710
return pigeonResult;
658711
}

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

Lines changed: 5 additions & 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.0.6), do not edit directly.
5+
// Autogenerated from Pigeon (v9.0.7), do not edit directly.
66
// See also: https://pub.dev/packages/pigeon
77

88
#import <Foundation/Foundation.h>
@@ -30,6 +30,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) {
3030
- (instancetype)init NS_UNAVAILABLE;
3131
+ (instancetype)makeWithABool:(NSNumber *)aBool
3232
anInt:(NSNumber *)anInt
33+
anInt64:(NSNumber *)anInt64
3334
aDouble:(NSNumber *)aDouble
3435
aByteArray:(FlutterStandardTypedData *)aByteArray
3536
a4ByteArray:(FlutterStandardTypedData *)a4ByteArray
@@ -41,6 +42,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) {
4142
aString:(NSString *)aString;
4243
@property(nonatomic, strong) NSNumber *aBool;
4344
@property(nonatomic, strong) NSNumber *anInt;
45+
@property(nonatomic, strong) NSNumber *anInt64;
4446
@property(nonatomic, strong) NSNumber *aDouble;
4547
@property(nonatomic, strong) FlutterStandardTypedData *aByteArray;
4648
@property(nonatomic, strong) FlutterStandardTypedData *a4ByteArray;
@@ -55,6 +57,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) {
5557
@interface AllNullableTypes : NSObject
5658
+ (instancetype)makeWithANullableBool:(nullable NSNumber *)aNullableBool
5759
aNullableInt:(nullable NSNumber *)aNullableInt
60+
aNullableInt64:(nullable NSNumber *)aNullableInt64
5861
aNullableDouble:(nullable NSNumber *)aNullableDouble
5962
aNullableByteArray:(nullable FlutterStandardTypedData *)aNullableByteArray
6063
aNullable4ByteArray:(nullable FlutterStandardTypedData *)aNullable4ByteArray
@@ -70,6 +73,7 @@ typedef NS_ENUM(NSUInteger, AnEnum) {
7073
aNullableString:(nullable NSString *)aNullableString;
7174
@property(nonatomic, strong, nullable) NSNumber *aNullableBool;
7275
@property(nonatomic, strong, nullable) NSNumber *aNullableInt;
76+
@property(nonatomic, strong, nullable) NSNumber *aNullableInt64;
7377
@property(nonatomic, strong, nullable) NSNumber *aNullableDouble;
7478
@property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullableByteArray;
7579
@property(nonatomic, strong, nullable) FlutterStandardTypedData *aNullable4ByteArray;

0 commit comments

Comments
 (0)