mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 00:55:11 +01:00
Bounds check consts by value, not type
This lets us prove "c == 123" given "pri const c u32 = 123". Fixes #5
This commit is contained in:
1 parent
911977228d
commit
e700bcd4f8
1 file changed
+11
-1
+11
-1
@@ -774,7 +774,17 @@ func (q *checker) bcheckExpr1(n *a.Expr, depth uint32) (*big.Int, *big.Int, erro
|
|||||||
func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) {
|
func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) {
|
||||||
switch n.Operator().Key() {
|
switch n.Operator().Key() {
|
||||||
case 0:
|
case 0:
|
||||||
// No-op.
|
// Look for named consts.
|
||||||
|
//
|
||||||
|
// TODO: look up "foo[i]" const expressions.
|
||||||
|
//
|
||||||
|
// TODO: allow imported consts, "foo.bar", not just "bar"?
|
||||||
|
qid := t.QID{0, n.Ident()}
|
||||||
|
if c, ok := q.c.consts[qid]; ok {
|
||||||
|
if cv := c.Value().ConstValue(); cv != nil {
|
||||||
|
return cv, cv, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case t.KeyOpenParen, t.KeyTry:
|
case t.KeyOpenParen, t.KeyTry:
|
||||||
if _, _, err := q.bcheckExpr(n.LHS().Expr(), depth); err != nil {
|
if _, _, err := q.bcheckExpr(n.LHS().Expr(), depth); err != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user