Open
Description
Previous ID | SR-8872 |
Radar | None |
Original Reporter | tonisuter (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Duplicate |
Environment
Apple Swift version 4.2 (swiftlang-1000.11.37.1 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.0.0
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug, TypeChecker |
Assignee | None |
Priority | Medium |
md5: 3b3eafa49c174723d8b51d86c02a1242
duplicates:
- SR-8696 Types nested in functions and their operator functions.
Issue Description:
Static operator functions don't work with local types. See the following example:
do {
struct S {
var x: Int
static func +(lhs: S, rhs: S) -> S {
return S(x: lhs.x + rhs.x)
}
}
let s1 = S(x: 1)
let s2 = S(x: 2)
print(s1 + s2) // error: binary operator '+' cannot
// be applied to two 'S' operands
}
It looks like these static operator functions are also ignored by the Equatable
/ Hashable
auto-synthesis. In the following example, auto-synthesis of the ==
operator function happens even though this function was declared manually:
do {
struct S: Equatable {
static func ==(lhs: S, rhs: S) -> Bool {
return false
}
}
print(S() == S()) // true (but should be false)
}