[swift-evolution] [Draft] Throwing Properties and Subscripts

Joe Groff jgroff at apple.com
Tue Mar 15 19:06:00 CDT 2016


> On Mar 15, 2016, at 5:01 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
> 
> 	extension Foo {
> 		static var readableProperties: [String: (inout Foo) -> inout Any] = [
> 			"readWriteProperty": { $0.readWriteProperty },
> 			"readWriteNonmutatingProperty": { ... },
> 			"readOnlyProperty": { ... },
> 			"readOnlyMutatingProperty": { ... }
> 		]
> 		static var writableProperties: [String: (inout Foo) -> inout Any] = [
> 			"readWriteProperty": {
> 				get { return $0.readWriteProperty }
> 				set { $0.readWriteProperty = newValue as! Int }
> 			},
> 			"readWriteNonmutatingProperty": { ... }
> 		]
> 	}

A mutable return has to be invariant. It'd be more sound to model that as "exists T. (inout Foo) -> inout T", if our type system becomes powerful enough to represent that, than to erase the return type, since you could then conceivably still recover the T by opening the existential. 

-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160315/99c8f457/attachment.html>


More information about the swift-evolution mailing list