[stdlib] removed ambiguous String comparison overloads

Fixes rdar://problem/19169066

Now that some implicit bridging conversions were removed, we can remove some of
the complex String comparison overloads. We could not remove all of them yet, as
String to NSString implicit bridging still exists. To work around this,
unavailable annotations were used. This ensures the user always gets the String
comparison function they intended.

Swift SVN r24536
This commit is contained in:
Maxwell Swadling
2015-01-19 23:18:07 +00:00
parent 97ec4ac5f1
commit 661fde2ca6
4 changed files with 36 additions and 59 deletions

View File

@@ -12,37 +12,26 @@
//
// Mixed-type comparisons between String and NSString.
// Since the compiler will implicitly bridge String to NSString, these more
// refined overloads exist to disable invalid bridging from happening.
// For example, swiftString < nsString will bridge swiftString to NSString
// and perform incorrect unicode comparison.
//
% for op in [ '==', '!=', '<', '<=', '>=', '>' ]:
@availability(*, unavailable,
message="Comparing Swift.String and NSString is ambiguous")
@transparent
public func ${op} (lhs: String, rhs: NSString) -> Bool {
// FIXME(performance): constructing a temporary string is extremely
// wasteful and inefficient.
return lhs ${op} (rhs as String)
fatalError("impossible")
}
@availability(*, unavailable,
message="Comparing Swift.String and NSString is ambiguous")
@transparent
public func ${op} (lhs: NSString, rhs: String) -> Bool {
// FIXME(performance): constructing a temporary string is extremely
// wasteful and inefficient.
return (lhs as String) ${op} rhs
fatalError("impossible")
}
% end
// This overload is required to disambiguate homogeneous NSString/NSString
// comparisons in non-generic code.
@transparent
public func == (lhs: NSString, rhs: NSString) -> Bool {
return lhs as NSObject == rhs as NSObject
}
// This overload is required to disambiguate homogeneous NSString/NSString
// comparisons in non-generic code.
@transparent
public func != (lhs: NSString, rhs: NSString) -> Bool {
return !(lhs == rhs)
}