Skip to content

Commit e16d689

Browse files
committed
[PrintAsObjC] Sentence-case the enum case name when appending it to the enum name.
Otherwise, we cram a conventionally UpperCamelCase thing with a newly-conventinally-lowerCamelCased thing together and destroy the word boundaries. Fixes rdar://problem/24947695.
1 parent 0af5640 commit e16d689

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/AST/PrettyStackTrace.h"
1919
#include "swift/AST/TypeVisitor.h"
2020
#include "swift/AST/Comment.h"
21+
#include "swift/Basic/StringExtras.h"
2122
#include "swift/Basic/Version.h"
2223
#include "swift/ClangImporter/ClangImporter.h"
2324
#include "swift/Frontend/Frontend.h"
@@ -264,7 +265,9 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
264265
} else {
265266
os << customName;
266267
}
267-
os << Elt->getName();
268+
269+
SmallString<16> scratch;
270+
os << camel_case::toSentencecase(Elt->getName().str(), scratch);
268271
} else {
269272
os << customEltName
270273
<< " SWIFT_COMPILE_NAME(\"" << Elt->getName() << "\")";

test/PrintAsObjC/enums.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ import Foundation
3636
// CHECK-NEXT: ObjcEnumNamedA = 0,
3737
// CHECK-NEXT: ObjcEnumNamedB = 1,
3838
// CHECK-NEXT: ObjcEnumNamedC = 2,
39+
// CHECK-NEXT: ObjcEnumNamedD = 3,
40+
// CHECK-NEXT: ObjcEnumNamedHelloDolly = 4,
3941
// CHECK-NEXT: };
4042

4143
@objc(ObjcEnumNamed) enum EnumNamed: Int {
42-
case A, B, C
44+
case A, B, C, d, helloDolly
4345
}
4446

4547
// CHECK-LABEL: typedef SWIFT_ENUM(NSInteger, EnumWithNamedConstants) {

0 commit comments

Comments
 (0)