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-10706] Operator behaves differently than equally defined function #53103

Open
BenchR267 opened this issue May 17, 2019 · 2 comments
Open
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

@BenchR267
Copy link
Member

Previous ID SR-10706
Radar rdar://50894095
Original Reporter @BenchR267
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 611771dfe696a0d4b9d2a1f4de0da224

Issue Description:

I played around with operators and found out that operators pick an overload with an `Any` operator while a function takes the better fitting statically typed version. See the following example:

protocol Bar {}
class A: Bar {}
let a = A()

// functions
func foo<T>(_ obj: T) where T: Bar {
    print("function with type constraint called")
}
func foo(_ obj: Any) {
    print("function with Any called")
}

// operators
prefix operator *
prefix func *<T>(_ obj: T) where T: Bar {
    print("operator with type constraint called")
}
prefix func *(_ obj: Any) {
    print("operator with Any called")
}

foo(a) // function with type constraint called
*a // operator with Any called

I would expect that *a would also take the version with a type constraint.

@belkadan
Copy link
Contributor

cc @xedin

@xedin
Copy link
Member

xedin commented May 17, 2019

Ah, this is related to operator only hack where solver stops after finding first matching non-generic overload choice, I think we should not do this for `Any` though.

@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

3 participants