[Swift-devel] Explicit subscript type declaration for arrays

Mihael Hategan hategan at mcs.anl.gov
Thu Jul 7 14:30:53 CDT 2011


On Fri, 2011-07-08 at 00:48 +0530, Yadu Nand wrote:
[...]
> 
> Right now, I'm checking for the basic types already defined as
> well as types found earlier on parsing(which I think is the right
> behavior), but these are not tested and will take a couple of
> days more.
> 
[...]
> 
> Mihael had pointed out a case in which a struct was used as
> subscript. How will such an array be declared ? I am blank
> about how struct types. Suggestions and ideas are welcome.
> ( I really need help! )

You could start with support for only primitive types as indices (i.e.
Type.isPrimitive()).

In terms of the structs, these look like.. structs:
type mystruct {
  int a;
  string b;
}

What's needed if they are to be used for array keys is an equality test,
which can be straightforwardly done in the struct case by comparing
field values recursively. Since non-primitive types cannot really be
compared properly at this time, this would probably mean that
non-primitive types should not be allowed in composite types that can be
array keys.




More information about the Swift-devel mailing list