Skip to content

Commit a54a7c0

Browse files
committed
[Clang importer] Restore historical definition of "Boolean for Objective-C"
The `isBoolType` operation within the Clang importer has a historical definition that excludes the C++ `bool` and its use in C as an extension. Retain that definition, and check for the actual `bool` when importing C++ conversion functions into Swift. Fixes two regressions in the Clang importer: 1. We started to import `bool`-typed Objective-C properties with their getter names. 2. We started importing `bool`-typed Objective-C methods with an NSError** parameter as `throws`. Both of these changes could be considered improvements, but they cannot be made without breaking source compatibility, so roll those changes back to maintain source compatibility. We should have a separate discussion about enabling this behavior for Swift >= 6.
1 parent d637362 commit a54a7c0

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

lib/ClangImporter/ImportName.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ static bool isErrorOutParameter(const clang::ParmVarDecl *param,
155155

156156
static bool isBoolType(clang::ASTContext &ctx, clang::QualType type) {
157157
do {
158-
if (type->isBooleanType())
159-
return true;
160-
161158
// Check whether we have a typedef for "BOOL" or "Boolean".
162159
if (auto typedefType = dyn_cast<clang::TypedefType>(type.getTypePtr())) {
163160
auto typedefDecl = typedefType->getDecl();
@@ -1857,7 +1854,7 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
18571854
return ImportedName();
18581855
auto toType = conversionDecl->getConversionType();
18591856
// Only import `operator bool()` for now.
1860-
if (isBoolType(clangSema.Context, toType)) {
1857+
if (toType->isBooleanType()) {
18611858
isFunction = true;
18621859
baseName = "__convertToBool";
18631860
addEmptyArgNamesForClangFunction(conversionDecl, argumentNames);

test/ClangImporter/objc_parse.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ func customAccessors(_ hive: Hive, bee: Bee) {
333333
hive.`guard` = bee // no-warning
334334
}
335335

336+
// Properties with bool don't use the getter.
337+
func boolProperties(_ hive: Hive) {
338+
markUsed(hive.empty)
339+
}
340+
336341
// instancetype/Dynamic Self invocation.
337342
func testDynamicSelf(_ queen: Bee, wobbler: NSWobbling) {
338343
var hive = Hive()

test/Inputs/clang-importer-sdk/usr/include/Foundation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#import <CoreFoundation.h>
88
#import <CoreGraphics.h>
99
#endif
10+
#import <stdbool.h>
1011

1112
#define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
1213

@@ -262,6 +263,7 @@ __attribute__((warn_unused_result)) NSString *NSStringToNSString(NSString *str);
262263
@property (nonnull) NSDictionary<id <NSCopying>, Bee *> *anythingToBees;
263264

264265
@property(getter=isMakingHoney) BOOL makingHoney;
266+
@property(readonly,getter=isEmpty) bool empty;
265267
@property(setter=assignGuard:) id guard;
266268

267269
+ (instancetype)hiveWithQueen:(Bee *)queen;

0 commit comments

Comments
 (0)