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-1775] Better handling of property/method name clashes #44384

Closed
swift-ci opened this issue Jun 15, 2016 · 4 comments
Closed

[SR-1775] Better handling of property/method name clashes #44384

swift-ci opened this issue Jun 15, 2016 · 4 comments
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-1775
Radar None
Original Reporter uraimo (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: fef16d35fd5d9c5fe9be8e350257d666

relates to:

  • SR-4587 No "inaccessible" diagnostic for property if the base name is shared with methods
  • SR-9916 Variable name same as function name

Issue Description:

Until Swift 2.2.1 this snippet compiled correctly and no errors were reported by SourceKit:

class TestClass{
    var p1: Int = 1
    func p1(a: Int) {
        print(a)
    }
}

let tc = TestClass()
print(tc.p1)
tc.p1(a:2)

But now both Xcode and the repl report this error when trying to call tc.p1(a:2):

error: cannot call value of non-function type 'Int'

When compiled with swiftc (even a recent june 3.0-dev) the code above still gets compiled cleanly without errors.

Since i suppose that we now want to disallow the use of the same name for a method and a property, this check should be performed in swiftc too and maybe the error should be shown when the class with the duplicated label it's declared (when the p1 func is declared?) instead than at its first use.

Note: And the `p1` function can still be called with (tc.p1 as (Int)->Void)(2), so, it this just an initial implementation of this error or it's the side-effect of other modifications in the way types are handled/resolved?

@belkadan
Copy link
Contributor

Hm. When you say "Xcode", do you mean a playground?

@swift-ci
Copy link
Collaborator Author

Comment by Umberto Raimondi (JIRA)

I get the same error with a playground and a simple macOS console project.

I'm using Xcode v7.3.1.

@swift-ci
Copy link
Collaborator Author

Comment by Slipp Douglas Thompson (JIRA)

With the addition of first(where: ) to Array/Collection/Sequence in Swift 3, this issue has been exacerbated— it now can occur in code with only routine standard library usage.

“Name your properties and methods differently” is no longer a viable workaround. I hope this might raise the severity/priority of this bug.

@belkadan
Copy link
Contributor

This one got fixed a while ago, sorry for not coming back to it!

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

No branches or pull requests

2 participants