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-4660] Methods on self should not block unambiguous calls to free functions #47237

Closed
airspeedswift opened this issue Apr 21, 2017 · 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

@airspeedswift
Copy link
Member

Previous ID SR-4660
Radar rdar://problem/31760660
Original Reporter @airspeedswift
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 12281a4d9a9ecf365a324aadbc5ac15d

duplicates:

  • SR-1772 File-level function with the same name as instance function not picked up by compiler

relates to:

  • SR-2777 Diagnostics missing when method name shadows a global function with a different signature.
  • SR-2758 Shadow stdlib method without warning

Issue Description:

If you have a method on self with the same basename, the compiler will refuse to let you call free functions without full qualification, even when the call is unambiguous due to an argument labels, arity, types etc. This makes for a frustrating user experience, and requires workarounds for source compatibility when introducing methods that shadow existing functions.

Most prominent case is calling max passing in two arguments inside an extension on a Sequence (which has a no-argument max function). Even though it's not ambiguous, you have to write Swift.max which is ugly and hard for new users to discover.

func foo(i: Int) { }

struct S {
  func foo() { }
  func bar() {
    // error: use of 'foo' refers to instance method 'foo()' rather than global function 'foo(i:)'
    foo(i: 1)
  }
}
@airspeedswift
Copy link
Member Author

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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

1 participant