[swift-evolution] SE-0025: Scoped Access Level, next steps

Shawn Erickson shawnce at gmail.com
Mon Mar 14 23:37:53 CDT 2016


On Mon, Mar 14, 2016 at 5:18 PM Chris Lattner via swift-evolution <
swift-evolution at swift.org> wrote:

> Per Doug’s email, the core team agrees we should make a change here, but
> would like some bikeshedding to happen on the replacement name for private.
>
> To summarize the place we’d like to end up:
>
> - “public” -> symbol visible outside the current module.
> - “internal” -> symbol visible within the current module.
> - unknown -> symbol visible within the current file.
> - “private” -> symbol visible within the current declaration (class,
> extension, etc).
>

More thinking out loud...

`public` -> exported from module
<omitted> -> module scoped (e.g. current internal)
`private` -> class, struct, etc. scoped (e.g. new private)
`private(file)` or `file` -> file scoped (e.g existing private)
`private(module)` or `module` or `internal` -> module scoped (e.g. current
internal)

public var foo = 0 // marks default getter and setter public

public var foo = 0 {  // marks default getter and setter public however...
  private set         // marks default setter private
}

var foo = 0 { // marks default getter and setter module scoped however...
  public get  // marks default getter public
  private set // marks default setter private
}

public var foo: Int { ... } // marks provided getter public, read-only

var foo: Int {        // marks provided getter and setter module scoped
however...
  public get { ... }  // marks provided getter public
  private set { ... } // marks provided setter private
}

public var foo: Int { // marks provided getter and setter public however...
  get { ... }         // not specified, inherit access level public
  private set { ... } // marks provided setter private
}

var foo: Int {        // marks provided getter and setter module scoped
however...
  get { ... }         // not specified, inherit access level module scoped
  private set { ... } // marks provided setter private
}

private(module) var foo: Int { // marks provided getter and setter module
scoped however...
  get { ... }                 // not specified, inherit access level module
scoped
  private(file) set { ... }   // marks provided setter file scoped
}

var foo: Int {                // marks provided getter and setter module
scoped however...
  private(file) get { ... }   // not specified, inherit access level module
scoped
  private set { ... }         // marks provided setter file scoped
}

...etc...

public subscript(index: Int) -> Int { ... } // marks provided getter
public, read-only

public subscript(index: Int) -> Int { // marks provided getter and setter
public
  get { ... }                         // not specified, inherit access
level public
  set { ... }                         // not specified, inherit access
level public
}

public subscript(index: Int) -> Int { // marks provided getter and setter
public however...
  get { ... }                         // not specified, inherit access
level public
  private set { ... }                 // marks provided setter private
}

subscript(index: Int) -> Int {  // marks provided getter and setter module
scoped however...
  get { ... }                   // not specified, inherit access level
module scoped
  private set { ... }           // marks provided setter private
}

subscript(index: Int) -> Int {  // marks provided getter and setter module
scoped however...
  public get { ... }            // marks provided getter public
  private set { ... }           // marks provided setter private
}

subscript(index: Int) -> Int {  // marks provided getter and setter module
scoped however...
  public get { ... }            // marks provided getter public
  private(file) set { ... }     // marks provided setter file scoped
}
...etc...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160315/8682bf77/attachment.html>


More information about the swift-evolution mailing list