Files
swift-mirror/stdlib/objc/Foundation/MixedStringNSStringOperations.swift.gyb
Doug Gregor 916e9a7eb5 Fix computation of “favored” constraints for binary expressions <rdar://problem/17943223>.
The determination of “favored” constraints for binary expressions was comparing the second argument to the first parameter to decide if the constraint is favored. Coupled with implicit bridging conversions through NSNumber, this meant that “1.0/10” would become Int when Foundation was imported, and hilarity ensued.

Fix the heuristic for favored constraints, tidy up this code a bit, and add ==(NSString, NSString) to cope with the ambiguity this creates.

Swift SVN r21154
2014-08-12 21:16:59 +00:00

49 lines
1.5 KiB
Swift

//===--- MixedStringNSStringOperations.swift.gyb --------------*- swift -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// Mixed-type comparisons between String and NSString.
//
% for op in [ '==', '!=', '<', '<=', '>=', '>' ]:
@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)
}
@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
}
% 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)
}