Skip to content

Commit 7b226ad

Browse files
committed
[Omit Needless Words] Don't remove a first argument label when the parameter has as default argument.
Parameters that have default arguments should have argument labels; don't remove them on import. Fixes rdar://problem/26611977.
1 parent 3dc42d7 commit 7b226ad

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

lib/Basic/StringExtras.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ bool swift::omitNeedlessWords(StringRef &baseName,
12541254
NameRole role = i > 0 ? NameRole::SubsequentParameter
12551255
: argNames[0].empty() ? NameRole::BaseName
12561256
: baseName == "init" ? NameRole::SubsequentParameter
1257+
: paramTypes[0].hasDefaultArgument() ? NameRole::SubsequentParameter
12571258
: NameRole::FirstParameter;
12581259

12591260
// Omit needless words from the name.

stdlib/public/SDK/Foundation/NSStringAPI.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,12 +1415,19 @@ extension String {
14151415
// stringByFoldingWithOptions:(NSStringCompareOptions)options
14161416
// locale:(NSLocale *)locale
14171417

1418+
@available(*, unavailable, renamed: "folding(options:locale:)")
1419+
public func folding(
1420+
_ options: NSStringCompareOptions = [], locale: NSLocale?
1421+
) -> String {
1422+
return folding(options: options, locale: locale)
1423+
}
1424+
14181425
/// Returns a string with the given character folding options
14191426
/// applied.
14201427
public func folding(
1421-
_ options: NSStringCompareOptions = [], locale: NSLocale?
1428+
options: NSStringCompareOptions = [], locale: NSLocale?
14221429
) -> String {
1423-
return _ns.folding(options, locale: locale)
1430+
return _ns.folding(options: options, locale: locale)
14241431
}
14251432

14261433
// - (NSString *)stringByPaddingToLength:(NSUInteger)newLength
@@ -1884,13 +1891,6 @@ extension String {
18841891
fatalError("unavailable function can't be called")
18851892
}
18861893

1887-
@available(*, unavailable, renamed: "folding(_:locale:)")
1888-
public func folding(
1889-
options: NSStringCompareOptions = [], locale: NSLocale?
1890-
) -> String {
1891-
fatalError("unavailable function can't be called")
1892-
}
1893-
18941894
@available(*, unavailable, renamed: "padding(toLength:with:startingAt:)")
18951895
public func byPaddingToLength(
18961896
_ newLength: Int, withString padString: String, startingAt padIndex: Int

test/1_stdlib/NSStringAPI.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,12 +1391,12 @@ NSStringAPIs.test("deletingLastPathComponent") {
13911391
expectEqual("/tmp", "/tmp/a.txt".deletingLastPathComponent)
13921392
}
13931393

1394-
NSStringAPIs.test("folding(_:locale:)") {
1394+
NSStringAPIs.test("folding(options:locale:)") {
13951395

13961396
func fwo(
13971397
_ s: String, _ options: NSStringCompareOptions
13981398
) -> (NSLocale?) -> String {
1399-
return { loc in s.folding(options, locale: loc) }
1399+
return { loc in s.folding(options: options, locale: loc) }
14001400
}
14011401

14021402
expectLocalizedEquality("abcd", fwo("abCD", .caseInsensitiveSearch), "en")

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
@interface SEGreebieArray : NSObject
88
@end
99

10+
typedef NS_OPTIONS(NSUInteger, OMWWobbleOptions) {
11+
OMWWobbleSideToSide = 0x01,
12+
OMWWobbleBackAndForth = 0x02
13+
};
14+
1015
@interface OmitNeedlessWords : NSObject
1116
-(void)jumpToUrl:(nonnull NSURL *)url;
1217
-(BOOL)objectIsCompatibleWithObject:(nonnull id)other;
@@ -35,6 +40,7 @@
3540
+(nonnull OmitNeedlessWords *)currentOmitNeedlessWords;
3641
+(void)setCurrentOmitNeedlessWords:(nonnull OmitNeedlessWords *)value;
3742
-(void)compilerPlugInValue:(NSInteger)value;
43+
-(void)wobbleWithOptions:(OMWWobbleOptions)options;
3844
@end
3945

4046
@interface ABCDoodle : NSObject

test/IDE/print_omit_needless_words.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
// CHECK-FOUNDATION: var isMakingHoney: Bool
7979

8080
// Note: multi-word enum name matching; "with" splits the first piece.
81-
// CHECK-FOUNDATION: func someMethod(_: DeprecatedOptions = [])
81+
// CHECK-FOUNDATION: func someMethod(deprecatedOptions: DeprecatedOptions = [])
8282

8383
// Note: class name matching; don't drop "With".
8484
// CHECK-FOUNDATION: class func withString(_: String!) -> Self!
@@ -135,10 +135,10 @@
135135

136136
// Note: usingBlock -> body
137137
// CHECK-FOUNDATION: func enumerateObjects(_: ((AnyObject?, Int, UnsafeMutablePointer<ObjCBool>?) -> Void)!)
138-
// CHECK-FOUNDATION: func enumerateObjects(_: EnumerationOptions = [], using: ((AnyObject?, Int, UnsafeMutablePointer<ObjCBool>?) -> Void)!)
138+
// CHECK-FOUNDATION: func enumerateObjects(options: EnumerationOptions = [], using: ((AnyObject?, Int, UnsafeMutablePointer<ObjCBool>?) -> Void)!)
139139

140140
// Note: WithBlock -> body, nullable closures default to nil.
141-
// CHECK-FOUNDATION: func enumerateObjectsRandomly(_: ((AnyObject?, Int, UnsafeMutablePointer<ObjCBool>?) -> Void)? = nil)
141+
// CHECK-FOUNDATION: func enumerateObjectsRandomly(block: ((AnyObject?, Int, UnsafeMutablePointer<ObjCBool>?) -> Void)? = nil)
142142

143143
// Note: id<Proto> treated as "Proto".
144144
// CHECK-FOUNDATION: func doSomething(with: Copying)
@@ -311,6 +311,10 @@
311311
// Don't split "PlugIn".
312312
// CHECK-OMIT-NEEDLESS-WORDS: func compilerPlugInValue(_: Int)
313313

314+
// Don't strip away argument label completely when there is a default
315+
// argument.
316+
// CHECK-OMIT-NEEDLESS-WORDS: func wobble(options: OMWWobbleOptions = [])
317+
314318
// Property-name sensitivity in the base name "Self" stripping.
315319
// CHECK-OMIT-NEEDLESS-WORDS: func addDoodle(_: ABCDoodle)
316320

0 commit comments

Comments
 (0)