Skip to content

Commit 8ea0796

Browse files
committed
[ClangImporter] Don't import C function pointer typedefs as bridged
We don't get to bridge C functions usually, so the typedef is more useful in its unbridged form. Undoes a change by John in 0e89efa.
1 parent 3555e32 commit 8ea0796

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

lib/ClangImporter/ImporterImpl.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,13 @@ enum class Bridgeability {
191191
Full
192192
};
193193

194+
/// Controls whether a typedef for \p type should name the fully-bridged Swift
195+
/// type or the original Clang type.
196+
///
197+
/// In either case we end up losing sugar at some uses sites, so this is more
198+
/// about what the right default is.
194199
static inline Bridgeability getTypedefBridgeability(clang::QualType type) {
195-
return (type->isBlockPointerType() || type->isFunctionType())
196-
? Bridgeability::Full
197-
: Bridgeability::None;
200+
return type->isBlockPointerType() ? Bridgeability::Full : Bridgeability::None;
198201
}
199202

200203
/// \brief Describes the kind of the C type that can be mapped to a stdlib

test/ClangImporter/Inputs/custom-modules/ObjCParseExtras.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,6 @@ typedef NSArray<NSString *> *NSStringArray;
209209
@interface BridgedTypedefs : NSObject
210210
@property (readonly,nonnull) NSArray<NSStringArray> *arrayOfArrayOfStrings;
211211
@end
212+
213+
typedef NSString * _Nonnull (*FPTypedef)(NSString * _Nonnull);
214+
extern FPTypedef _Nonnull getFP(void);

test/ClangImporter/objc_parse.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,9 @@ func testTypeAndValue() {
643643
func testBridgedTypedef(bt: BridgedTypedefs) {
644644
let _: Int = bt.arrayOfArrayOfStrings // expected-error{{'[[String]]'}}
645645
}
646+
647+
func testBridgeFunctionPointerTypedefs(fptrTypedef: FPTypedef) {
648+
// See also print_clang_bool_bridging.swift.
649+
let _: Int = fptrTypedef // expected-error{{'@convention(c) (String) -> String'}}
650+
let _: Int = getFP() // expected-error{{'@convention(c) (String) -> String'}}
651+
}

0 commit comments

Comments
 (0)