Permit maps in IDL

This commit is contained in:
joeduffy 2017-04-28 15:03:09 -07:00
parent e2e73cf035
commit 7e057cd1b5

View file

@ -356,6 +356,22 @@ func (chk *Checker) CheckIDLType(t types.Type, opts PropertyOptions) error {
return errors.New("bad pointer; must be optional or a resource type")
}
}
case *types.Map:
// A map is OK so long as its key is a string (or string-backed type) and its element type is okay.
isstr := false
switch kt := ft.Key().(type) {
case *types.Basic:
isstr = (kt.Kind() == types.String)
case *types.Named:
if bt, isbt := kt.Underlying().(*types.Basic); isbt {
isstr = (bt.Kind() == types.String)
}
}
if !isstr {
return errors.Errorf("map index type %v must be a string (or string-backed typedef)", ft.Key())
}
return chk.CheckIDLType(ft.Elem(), PropertyOptions{})
case *types.Slice:
// A slice is OK so long as its element type is also OK.
return chk.CheckIDLType(ft.Elem(), PropertyOptions{})