From e930d668972e5a7513630dee1b120c4b1efeb3a1 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Mon, 5 Jun 2023 13:33:15 +1000 Subject: [PATCH] lang: reject 0-length arrays --- lang/check/type.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lang/check/type.go b/lang/check/type.go index 3e9fed64..4a47b104 100644 --- a/lang/check/type.go +++ b/lang/check/type.go @@ -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