From e700bcd4f897b5d6512c6c59880770a5903a8541 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sat, 31 Mar 2018 16:43:53 +1100 Subject: [PATCH] Bounds check consts by value, not type This lets us prove "c == 123" given "pri const c u32 = 123". Fixes #5 --- lang/check/bounds.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lang/check/bounds.go b/lang/check/bounds.go index 74db9f58..cde3fbc1 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -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 {