Skip to content

Commit

Permalink
Fix #1701
Browse files Browse the repository at this point in the history
  • Loading branch information
liamappelbe committed Nov 13, 2024
1 parent 6793812 commit 05ebff0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkgs/ffigen/lib/src/code_generator/objc_nullable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ class ObjCNullable extends Type {
Type child;

ObjCNullable(this.child)
: assert(isSupported(child.typealiasType),
: assert(isSupported(child),
'Nullable ${child.typealiasType.runtimeType} is not supported');

static bool isSupported(Type type) =>
static bool isSupported(Type type) => _isSupported(type.typealiasType);
static bool _isSupported(Type type) =>
type is ObjCInterface ||
type is ObjCBlock ||
type is ObjCObjectPointer ||
Expand Down
6 changes: 6 additions & 0 deletions pkgs/ffigen/test/native_objc_test/nullable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,11 @@ void main() {
false);
});
});

test('Nullable typealias', () {
// Regression test for https://github.com/dart-lang/native/issues/1701
expect(NullableInterface.returnNullableAlias_(true), isNull);
expect(NullableInterface.returnNullableAlias_(false)?.toString(), "Hi");
});
});
}
11 changes: 11 additions & 0 deletions pkgs/ffigen/test/native_objc_test/nullable_test.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#import <Foundation/NSObject.h>

typedef NSString* MyString;

@interface NullableInterface : NSObject {
}

+(BOOL) isNullWithNullableNSObjectArg:(nullable NSObject *)x;
+(BOOL) isNullWithNotNullableNSObjectPtrArg:(NSObject *)x;
+(BOOL) isNullWithExplicitNonNullableNSObjectPtrArg:(nonnull NSObject *)x;
+(nullable NSObject *) returnNil:(BOOL)r;
+(nullable MyString) returnNullableAlias:(BOOL)r;

@property (nullable, retain) NSObject *nullableObjectProperty;

Expand Down Expand Up @@ -34,4 +37,12 @@ +(nullable NSObject *) returnNil:(BOOL)r {
}
}

+(nullable MyString) returnNullableAlias:(BOOL)r {
if (r) {
return nil;
} else {
return @"Hi";
}
}

@end

0 comments on commit 05ebff0

Please sign in to comment.