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

+21 -3
View File
@@ -953,10 +953,28 @@ func (q *checker) bcheckExpr1(n *a.Expr, depth uint32) (bounds, error) {
case op.IsXUnaryOp():
return q.bcheckExprUnaryOp(n, depth)
case op.IsXBinaryOp():
if op == t.IDXBinaryAs {
return q.bcheckExpr(n.LHS().AsExpr(), depth)
if op != t.IDXBinaryAs {
return q.bcheckExprBinaryOp(op, n.LHS().AsExpr(), n.RHS().AsExpr(), depth)
}
return q.bcheckExprBinaryOp(op, n.LHS().AsExpr(), n.RHS().AsExpr(), depth)
b, err := q.bcheckExpr(n.LHS().AsExpr(), depth)
if err != nil {
return bounds{}, err
} else if lhs := n.LHS().AsExpr(); lhs.MType().IsEitherSliceType() {
cv := (*big.Int)(nil)
rhs := n.RHS().AsTypeExpr()
if (rhs.Decorator() == t.IDPtr) && (rhs.Inner().IsEitherArrayType()) {
cv = rhs.Inner().ArrayLength().ConstValue()
}
if cv == nil {
// TODO: fix this.
return bounds{}, fmt.Errorf("check: cannot bounds-check conversion to %q", rhs.Str(q.tm))
}
if err := q.proveSliceLengthAtLeast(lhs, cv); err != nil {
return bounds{}, err
}
b = bounds{one, maxPointerBounds}
}
return b, nil
case op.IsXAssociativeOp():
return q.bcheckExprAssociativeOp(n, depth)
}