Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-8872] Operators for local types not working #51378

Open
swift-ci opened this issue Sep 28, 2018 · 1 comment
Open

[SR-8872] Operators for local types not working #51378

swift-ci opened this issue Sep 28, 2018 · 1 comment
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself expressions Feature: expressions name lookup Area → compiler → type checker: Name lookup operators Feature: operators swift 5.9 type checker Area → compiler: Semantic analysis unexpected behavior Bug: Unexpected behavior or incorrect output

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 28, 2018

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)
}
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis
Copy link
Collaborator

AnthonyLatsis commented Jun 3, 2022

Reopening this because it only partially duplicates #51209. The first example is a related, but independent issue.

@AnthonyLatsis AnthonyLatsis reopened this Jun 3, 2022
@AnthonyLatsis AnthonyLatsis self-assigned this Feb 22, 2023
@AnthonyLatsis AnthonyLatsis added operators Feature: operators name lookup Area → compiler → type checker: Name lookup expressions Feature: expressions unexpected behavior Bug: Unexpected behavior or incorrect output swift 5.9 labels Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself expressions Feature: expressions name lookup Area → compiler → type checker: Name lookup operators Feature: operators swift 5.9 type checker Area → compiler: Semantic analysis unexpected behavior Bug: Unexpected behavior or incorrect output
Projects
None yet
Development

No branches or pull requests

2 participants