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-11078] Property and class can't share names. #53470

Open
swift-ci opened this issue Jul 7, 2019 · 1 comment
Open

[SR-11078] Property and class can't share names. #53470

swift-ci opened this issue Jul 7, 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

swift-ci commented Jul 7, 2019

Previous ID SR-11078
Radar None
Original Reporter katsz (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 4a7afb191de74a1422b15e5e93efa6fd

relates to:

  • SR-1687 Swift does not warn about shadowing

Issue Description:

Let's say there is some class Foo with a constructor. It may or may not have any arguments, the only thing matter it should be accessible from class Bar. If Bar has property let Foo: AnyTypeDoesNotMatter then any attempt to initialize an instance of class Foo will be considered by compiler as an attempt to access property self.Foo

For example:

class Foo {
    public init() {
        
    }
}

class Bar {
    let Foo = 0
    
    func someMethod() {
        let foo = Foo()
    }
}

will fail at line let foo = Foo() with error "cannot call value of non-function type 'Int'".
(Exact error may depends on context)

disclaimer: I'm more than aware that variable names should starts with lowercased letter. But if it compiles, it's valid. I've faced this issue when found out dependency conflict was caused by the fact that one of my libraries has class Foo and second one uses public extension of Bar with unconventional names for computable property var Foo. Compile error was irrelevant because I was not aware of any extensions for that matter.

@belkadan
Copy link
Contributor

belkadan commented Jul 8, 2019

You can get to the top-level names by using the name of your module as qualification, e.g. MyApp.Foo().

@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