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:
Nigel Tao committed 2018-03-31 16:43:53 +11:00
1 parent 911977228d
commit e700bcd4f8
1 file changed
+11 -1
+11 -1
View File
@@ -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) {
switch n.Operator().Key() {
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:
if _, _, err := q.bcheckExpr(n.LHS().Expr(), depth); err != nil {