Skip to content

Commit de7ef4b

Browse files
committed
[Clang importer] Don't prefix-strip notification names.
1 parent b4a5865 commit de7ef4b

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,18 +2318,25 @@ static clang::SwiftNameAttr *findSwiftNameAttr(const clang::Decl *decl,
23182318

23192319
/// Prepare global name for importing onto a swift_newtype.
23202320
static StringRef determineSwiftNewtypeBaseName(StringRef baseName,
2321-
StringRef newtypeName) {
2322-
baseName = stripLeadingK(baseName);
2323-
2324-
bool nonIdentifier = false;
2325-
auto pre = getCommonWordPrefix(newtypeName, baseName, nonIdentifier);
2326-
if (pre.size())
2327-
baseName = baseName.drop_front(pre.size());
2321+
StringRef newtypeName,
2322+
bool &strippedPrefix) {
2323+
StringRef newBaseName = stripLeadingK(baseName);
2324+
if (newBaseName != baseName) {
2325+
baseName = newBaseName;
2326+
strippedPrefix = true;
2327+
}
23282328

23292329
// Special case: Strip Notification for NSNotificationName
23302330
auto stripped = stripNotification(baseName);
23312331
if (!stripped.empty())
2332-
baseName = stripped;
2332+
return stripped;
2333+
2334+
bool nonIdentifier = false;
2335+
auto pre = getCommonWordPrefix(newtypeName, baseName, nonIdentifier);
2336+
if (pre.size()) {
2337+
baseName = baseName.drop_front(pre.size());
2338+
strippedPrefix = true;
2339+
}
23332340

23342341
return baseName;
23352342
}
@@ -2822,8 +2829,8 @@ auto ClangImporter::Implementation::importFullName(
28222829
// swift_newtype-ed declarations may have common words with the type name
28232830
// stripped.
28242831
if (auto newtypeDecl = findSwiftNewtype(D, clangSema, swift2Name)) {
2825-
baseName = determineSwiftNewtypeBaseName(baseName, newtypeDecl->getName());
2826-
strippedPrefix = true;
2832+
baseName = determineSwiftNewtypeBaseName(baseName, newtypeDecl->getName(),
2833+
strippedPrefix);
28272834
}
28282835

28292836
if (!result.isSubscriptAccessor() && !swift2Name) {

test/IDE/Inputs/custom-modules/Newtype.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ extern NSURLResourceKey const NSURLLocalizedNameKey;
4040
// Special case: Notifications
4141
extern const NSString *FooNotification;
4242
extern const NSString *kBarNotification;
43+
extern const NSString *NSWibbleNotification;
4344

4445
// But not just 'Notification'
4546
extern const NSString *kNotification;

test/IDE/newtype.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@
5454
// PRINT-NEXT: static let localizedNameKey: NSURLResourceKey
5555
// PRINT-NEXT: }
5656
// PRINT-NEXT: extension NSNotificationName {
57-
// PRINT-NEXT: static let foo: NSNotificationName
57+
// PRINT-NEXT: static let Foo: NSNotificationName
5858
// PRINT-NEXT: static let bar: NSNotificationName
59+
// PRINT-NEXT: static let NSWibble: NSNotificationName
5960
// PRINT-NEXT: }
6061
// PRINT-NEXT: let kNotification: String
6162
// PRINT-NEXT: let Notification: String
@@ -79,7 +80,7 @@ func tests() {
7980
let _ = ErrorDomain(rawValue: thirdEnum.rawValue!)
8081
let _ = ClosedEnum(rawValue: errOne.rawValue)
8182

82-
let _ = NSNotificationName.foo
83+
let _ = NSNotificationName.Foo
8384
let _ = NSNotificationName.bar
8485
}
8586

test/IRGen/newtype.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public func getErrorDomain() -> ErrorDomain {
1414

1515
// CHECK-LABEL: _TF7newtype6getFooFT_VSC18NSNotificationName
1616
public func getFoo() -> NSNotificationName {
17-
return NSNotificationName.foo
17+
return NSNotificationName.Foo
1818
// CHECK: load {{.*}} @FooNotification
1919
// CHECK: ret
2020
}

0 commit comments

Comments
 (0)