lang: reject 0-length arrays

This commit is contained in:
Nigel Tao committed 2023-06-05 13:33:15 +10:00
1 parent 4a2f570d56
commit e930d66897
1 file changed
+3 -1
+3 -1
View File
@@ -1186,8 +1186,10 @@ swtch:
if err := q.tcheckExpr(aLen, 0); err != nil {
return err
}
if aLen.ConstValue() == nil {
if cv := aLen.ConstValue(); cv == nil {
return fmt.Errorf("check: %q is not constant", aLen.Str(q.tm))
} else if cv.Sign() <= 0 {
return fmt.Errorf("check: array length %q is not positive", aLen.Str(q.tm))
}
fallthrough