lang: allow "slice_var as ptr array[etc] etc"

This commit is contained in:
Nigel Tao committed 2023-06-13 22:38:25 +10:00
1 parent 6411561deb
commit 19f56ebfd2
7 files changed
+83 -5

No files matched your search

+13
View File
@@ -17,6 +17,7 @@ package check
import (
"errors"
"fmt"
"math/big"
a "github.com/google/wuffs/lang/ast"
t "github.com/google/wuffs/lang/token"
@@ -382,3 +383,15 @@ func (q *checker) proveRecvNotEqNullptr(recv *a.Expr) error {
}
return fmt.Errorf("check: cannot prove %q", recv.Str(q.tm)+" <> nullptr")
}
func (q *checker) proveSliceLengthAtLeast(n *a.Expr, minInclLength *big.Int) error {
if (n.Operator() == t.IDDotDot) && (n.MHS() == nil) && (n.RHS() == nil) {
if lTyp := n.LHS().AsExpr().MType(); lTyp.IsEitherArrayType() &&
lTyp.ArrayLength().ConstValue().Cmp(minInclLength) >= 0 {
return nil
}
}
// TODO: the general case, where n isn't "foo[..]" and foo isn't an array
// of length >= minInclLength.
return fmt.Errorf("check: cannot prove %q", n.Str(q.tm)+".length() >= "+minInclLength.String())
}