[swift-evolution] [swift-evolution-announce] [Review] SE-0025 Scoped Access Level
Ilya Belenkiy
ilya.belenkiy at gmail.com
Fri Mar 4 16:44:40 CST 2016
A very important property of the proposal is that anything declared
"scoped" is completely sealed inside its scope and cannot be accessed from
the outside. This means that the scope can be moved anywhere in the file
without the danger of introducing access to implementation details.
Allowing a containing scope to see "scoped" in its inner scope would mean
that someone could just wrap a scope in another scope to gain access to
implementation details without changing anything in the scope itself. The
whole point of the proposal is to protect against something like this and
make sure that implementation details remain hidden from anything outside
the scope.
On Fri, Mar 4, 2016 at 4:37 PM Brent Royal-Gordon via swift-evolution <
swift-evolution at swift.org> wrote:
> > Currently there is no (good) way to limit extension methods to use only
> within the containing extension. I think the added clarity of a
> compiler-enforced access to “local” extension methods will be a solid win.
>
> I'm seeing a lot of people say "I want to keep things private to a
> particular extension within a file". I'm still not convinced if that's a
> worthy goal, but if it's what people want, I'd like to suggest an alternate
> semantic: `scoped` limits visibility to a particular top-level declaration
> block and all of the blocks nested inside it. That is, `local` declarations
> in a nested block are visible to the blocks it's inside, up to but not
> including the file scope.
>
> class Foo {
> struct Bar {
> var parentFoo: Foo
> }
> var myBar: Bar
>
> // Here, neither of the implementationDetails is visible.
> }
>
> extension Foo {
> func doSomething() {
> myBar.implementationDetail1()
> }
>
> extension Bar {
> scoped func implementationDetail1() {
> parentFoo.implementationDetail2()
> }
> }
>
> scoped func implementationDetail2() {
> print("All this compiles!")
> }
> }
>
> extension Foo {
> // Here, neither of the implementationDetails is visible.
> }
>
> --
> Brent Royal-Gordon
> Architechies
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160304/e2e1c793/attachment.html>
More information about the swift-evolution
mailing list