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-3209] Ambiguous use of binary operators not reported as error #45797

Open
swift-ci opened this issue Nov 15, 2016 · 1 comment
Open

[SR-3209] Ambiguous use of binary operators not reported as error #45797

swift-ci opened this issue Nov 15, 2016 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-3209
Radar rdar://problem/29318670
Original Reporter tonisuter (JIRA User)
Type Bug
Environment

Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 4f87677813e0a801d8190d5f53f9af3c

Issue Description:

The compiler should report an error for the following code:

infix operator ***: MultiplicationPrecedence
infix operator +++: AdditionPrecedence

func ***(x: Int, y: Int) -> String {
    print("f1")
    return ""
}

func ***(x: Int, y: Int) -> Int {
    print("f2")
    return 0
}

func +++(x: String, y: Int) -> Int {
    print("f3")
    return 0
}

func +++(x: Int, y: Int) -> Int {
    print("f4")
    return 0
}

let result = 0 *** 4 +++ 0      // prints f2 and f4

The overload resolution picks the functions f2 and f4 even though f1 and f3 would also be a valid pick. Additionally, both solutions should have the same priority / score and therefore the compiler should report this use of the operators *** and +++ as ambiguous.

@rudkx
Copy link
Member

rudkx commented May 5, 2017

This looks like the result of bailing out because of finding a solution using the default literal types.

Replacing the literals with Int-typed variables results in the ambiguity.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants