[swift-evolution] Invariant checks on strong typedefs?

Daryle Walker darylew at mac.com
Thu Jun 29 18:32:28 CDT 2017


In my retype idea, you can bring back symbols from the implementation type with an "export" command. There's an "export default" command to bring back all the numbered fields of a tuple or all the cases of an enum. But what would it mean to NOT include all enum cases?

One option is to ban this; a retype of an enumeration gets all cases automatically, no need to be explicit nor any way to exclude. But I think leaving it in is cooler; we can make a retype be a restricted type relative to its implementation type. Now there would be a new problem. What happens when we have a retyped object pose as its original type, but assign it a case value banned in the retype?  How would we let the object check its invariant, if at all (i.e. leave it quasi-undefined behavior)? How would we implement any rejection, a throw?

I was thinking of a special method. And it would apply to any retype; not just enumerations, but tuples and structs too. 

Sent from my iPhone


More information about the swift-evolution mailing list