Tighten struct field restrictions re pointers.

This commit is contained in:
Nigel Tao committed 2017-09-28 11:48:27 +10:00
1 parent 95391533b3
commit 0dd7aaf56c
1 file changed
+3 -8
+3 -8
View File
@@ -382,14 +382,9 @@ func (c *Checker) checkFields(fields []*a.Node, banPtrTypes bool) error {
if err := q.tcheckTypeExpr(f.XType(), 0); err != nil {
return fmt.Errorf("%v in field %q", err, f.Name().String(c.tm))
}
if banPtrTypes {
for x := f.XType(); x.Inner() != nil; x = x.Inner() {
if x.Decorator().Key() == t.KeyPtr {
// TODO: implement nptr (nullable pointer) types.
return fmt.Errorf("check: ptr type %q not allowed for field %q; use nptr instead",
x.String(c.tm), f.Name().String(c.tm))
}
}
if banPtrTypes && f.XType().HasPointers() {
return fmt.Errorf("check: pointer-containing type %q not allowed for field %q",
f.XType().String(c.tm), f.Name().String(c.tm))
}
if dv := f.DefaultValue(); dv != nil {
if f.XType().Decorator() != 0 {