Skip to content

[Clang importer] Fix bridging of the underlying types of typedefs. #12680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 4 additions & 9 deletions lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,18 +684,13 @@ namespace {
auto typedefBridgeability = getTypedefBridgeability(underlyingType);

// Figure out the typedef we should actually use.
auto underlyingBridgeability =
(Bridging == Bridgeability::Full
? typedefBridgeability : Bridgeability::None);
SwiftTypeConverter innerConverter(Impl, AllowNSUIntegerAsInt,
underlyingBridgeability);
SwiftTypeConverter innerConverter(Impl, AllowNSUIntegerAsInt, Bridging);
auto underlyingResult = innerConverter.Visit(underlyingType);

// If we used different bridgeability than this typedef normally
// would because we're in a non-bridgeable context, and therefore
// the underlying type is different from the mapping of the typedef,
// use the underlying type.
if (underlyingBridgeability != typedefBridgeability &&
// would, and therefore the underlying type is different from the
// mapping of the typedef, use the underlying type.
if (Bridging != typedefBridgeability &&
!underlyingResult.AbstractType->isEqual(mappedType)) {
return underlyingResult;
}
Expand Down
6 changes: 6 additions & 0 deletions test/ClangImporter/Inputs/custom-modules/ObjCParseExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,9 @@ typedef SomeCell <NSCopying> *CopyableSomeCell;
@property (class, readonly) InstancetypeAccessor *prop;
+ (instancetype)prop;
@end

typedef NSArray<NSString *> *NSStringArray;

@interface BridgedTypedefs : NSObject
@property (readonly,nonnull) NSArray<NSStringArray> *arrayOfArrayOfStrings;
@end
5 changes: 5 additions & 0 deletions test/ClangImporter/objc_parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,8 @@ func testTypeAndValue() {
let _: () -> testStruct = testStruct.init
let _: (CInt) -> testStruct = testStruct.init
}

// rdar://problem/34913507
func testBridgedTypedef(bt: BridgedTypedefs) {
let _: Int = bt.arrayOfArrayOfStrings // expected-error{{'[[String]]'}}
}