Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkgs/ffigen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
`Declarations.includeMemberSet`, `Declarations.useOriginalName`,
`Declarations.renameWithMap`, `Declarations.useMemberOriginalName`, and
`Declarations.renameMemberWithMap`.
- Fix [a bug](https://github.com/dart-lang/native/issues/2761) in imported
NS_OPTIONS enums.

## 20.0.0

Expand Down
6 changes: 3 additions & 3 deletions pkgs/ffigen/lib/src/code_generator/enum_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ class EnumClass extends BindingType with HasLocalScope {

@override
String getDartType(Context context) {
if (isObjCImport) {
return '${context.libs.prefix(objcPkgImport)}.$name';
} else if (style == EnumStyle.intConstants) {
if (style == EnumStyle.intConstants) {
return nativeType.getDartType(context);
} else if (isObjCImport) {
return '${context.libs.prefix(objcPkgImport)}.$name';
} else {
return name;
}
Expand Down
3 changes: 3 additions & 0 deletions pkgs/ffigen/test/native_objc_test/enum_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ enums:
include:
- Fruit
- CoffeeOptions
objc-interfaces:
include:
- EnumTestInterface
headers:
entry-points:
- 'enum_test.m'
37 changes: 37 additions & 0 deletions pkgs/ffigen/test/native_objc_test/enum_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ import 'util.dart';
void main() {
group('enum', () {
setUpAll(() {
// TODO(https://github.com/dart-lang/native/issues/1068): Remove this.
DynamicLibrary.open(
path.join(
packagePathForTests,
'..',
'objective_c',
'test',
'objective_c.dylib',
),
);
final dylib = File(
path.join(
packagePathForTests,
'test',
'native_objc_test',
'objc_test.dylib',
),
);
verifySetupFile(dylib);
DynamicLibrary.open(dylib.absolute.path);
generateBindingsForCoverage('enum');
});

Expand All @@ -33,5 +53,22 @@ void main() {
5,
);
});

test('Imported enum', () {
// Regression test for https://github.com/dart-lang/native/issues/2761
expect(
EnumTestInterface.useImportedNSEnum(
NSQualityOfService.NSQualityOfServiceUtility,
),
17,
);
expect(
EnumTestInterface.useImportedNSOptions(
NSOrderedCollectionDifferenceCalculationOptions
.NSOrderedCollectionDifferenceCalculationOmitInsertedObjects,
),
1,
);
});
});
}
22 changes: 22 additions & 0 deletions pkgs/ffigen/test/native_objc_test/enum_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#import <Foundation/NSArray.h>
#import <Foundation/NSObject.h>

typedef NS_ENUM(NSInteger, Fruit) {
Expand All @@ -17,3 +18,24 @@ typedef NS_OPTIONS(NSUInteger, CoffeeOptions) {
CoffeeOptionsSugar = 1 << 1,
CoffeeOptionsIced = 1 << 2,
};

@interface EnumTestInterface : NSObject {}

+(int32_t)useImportedNSEnum:(NSQualityOfService)x;
+(int32_t)useImportedNSOptions:
(NSOrderedCollectionDifferenceCalculationOptions)x;

@end

@implementation EnumTestInterface

+(int32_t)useImportedNSEnum:(NSQualityOfService)x {
return (int32_t)x;
}

+(int32_t)useImportedNSOptions:
(NSOrderedCollectionDifferenceCalculationOptions)x {
return (int32_t)x;
}

@end