Skip to content

[SR-4138] Static properties are allowed to use without qualifier in initializer of instance property #46721

@swift-ci

Description

@swift-ci
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*/
  } 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions