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-4138] Static properties are allowed to use without qualifier in initializer of instance property #46721

Open
swift-ci opened this issue Mar 2, 2017 · 2 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

swift-ci commented Mar 2, 2017

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

md5: c9706e2038e23de6e1ecffd1c78b09da

relates to:

  • SR-4559 Method called 'self' can be confused with regular 'self'

Issue Description:

Swift 3 forbids to use static members without qualifier in instance context. But it's still allowed to use static properties in initializers of instance properties (though it's forbidden to use static methods there)

An example:

class A {
  static var staticProp = 0
  static func staticFunc()->Int { return 0 }

  var instanceProp = staticProp /*allowed*/ + staticFunc() /*forbidden*/
  var instanceComputedProp: Int { staticProp /*forbidden*/ + staticFunc() /*forbidden*/ }
  func instanceFunc() {
    var _ = staticProp/*forbidden*/ + staticFunc()/*forbidden*/
  } 
}
@belkadan
Copy link
Contributor

belkadan commented Mar 3, 2017

@jckarter, we have dups for this, right?

@jckarter
Copy link
Member

jckarter commented Mar 3, 2017

I don't recall this exact problem, but it's related to the problems with referring to `self` in `lazy` property initializers. The initializer expressions are evaluated as if they're in static rather than instance context, with some not-terribly-principled hacks to try to use instance context in certain situations.

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

3 participants