[swift-evolution] [swift-evolution-announce] [Review] SE-0025 Scoped Access Level

Brent Royal-Gordon brent at architechies.com
Fri Mar 4 15:37:01 CST 2016


> 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



More information about the swift-evolution mailing list