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-9916] Variable name same as function name #52322

Open
swift-ci opened this issue Feb 13, 2019 · 1 comment
Open

[SR-9916] Variable name same as function name #52322

swift-ci opened this issue Feb 13, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-9916
Radar None
Original Reporter prashantkt (JIRA User)
Type Bug
Environment

Swift 4.2

XCode 10

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

md5: 020949e93fb879241aa7d36764f82f7d

relates to:

  • SR-4587 No "inaccessible" diagnostic for property if the base name is shared with methods
  • SR-1775 Better handling of property/method name clashes

Issue Description:

 class AClass {
 var add: (Int) -> Int {
 return
{ num in return num + 1 }
}
func add(_ num: Int) -> Int {
 return num + 20
 }
}

Now in some other place I have this code:

let a = AClass()
 print(a.add(1)) 

I have run this code, and the result is 2 (which means the variable's block is called).

So here are the questions:

  1. Does the compile always get the variable rather than call the function?
  1. Is there any way to call the function?
@belkadan
Copy link
Contributor

You can get to the function by referring to it by full name in this case…

let add = a.add(_:)
print(add(1))

…but that's not a good general answer.

@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
Projects
None yet
Development

No branches or pull requests

2 participants