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-4615] Inconsistent behavior resolving property with same name as static property #47192

Open
NachoSoto opened this issue Apr 18, 2017 · 6 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@NachoSoto
Copy link
Contributor

Previous ID SR-4615
Radar rdar://problem/31671776
Original Reporter @NachoSoto
Type Bug

Attachment: Download

Environment

Swift version 3.1 (swiftlang-802.0.51 clang-802.0.41)

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

md5: 966e77bffcb4ee5e543ab440633d7473

Issue Description:

The following code compiles:

class B {
    var a: Int? = nil
}

final class C: B {
    override init() {
        super.init()

        self.a = C.a
    }

    private static let a: Int = 0
}

However, if B and C are in different modules, this produces:
"Static member 'a' cannot be used on instance of type 'B'".

In the words of @jckarter: "maybe we don't query other modules if we find results in the current".

@AliSoftware
Copy link
Contributor

For reference, this seems to be similar to a bug we were having in Reusable, adding a storyboard type property to UIViewController but the compiler could not see it but only the instance property declared in UIKit

See GitHub issue here: AliSoftware/Reusable#33 (comment)

(not sure if the OP ended up filling Jira as I suggested them at that time?)

@jckarter
Copy link
Member

@swift-ci create

@swift-ci
Copy link
Collaborator

Comment by Graydon Hoare (JIRA)

Simplified testcase:

open class B {
    public var a: Int? = nil
}
import M
class C: B {
     func foo() {
    self.a = 0
     }
    static let a: Int = 0
}

Then run:

$ swiftc -module-name M -emit-module file1.swift
$ swiftc -I . file2.swift

@swift-ci
Copy link
Collaborator

Comment by Graydon Hoare (JIRA)

Also worth noting in this case a workaround is to access super.a rather than self.a.

@NachoSoto
Copy link
Contributor Author

Would that call the `didSet` of an overridden `a: Int`?

@swift-ci
Copy link
Collaborator

Comment by Graydon Hoare (JIRA)

Not sure I understand; if you override the instance property a:Int in the subclass (i.e. with a computed property) there's no shadowing, the access resolves to the override. The only bug here (which I agree, may well be a bug) is when the static property of the subclass incorrectly shadows a non-overridden instance property of the superclass.

Am I misunderstanding the question?

@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

4 participants