mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 08:38:14 +01:00
Allow scalar constants in type expressions
This commit is contained in:
1 parent
278200f560
commit
8bbdcc4ce1
7 files changed
+58
-18
No files matched your search
+17
-2
@@ -932,7 +932,7 @@ swtch:
|
||||
if err := q.tcheckExpr(b, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if b.ConstValue() == nil {
|
||||
if q.exprConstValue(b) == nil {
|
||||
return fmt.Errorf("check: %q is not constant", b.Str(q.tm))
|
||||
}
|
||||
}
|
||||
@@ -958,7 +958,7 @@ swtch:
|
||||
if err := q.tcheckExpr(aLen, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if aLen.ConstValue() == nil {
|
||||
if q.exprConstValue(aLen) == nil {
|
||||
return fmt.Errorf("check: %q is not constant", aLen.Str(q.tm))
|
||||
}
|
||||
fallthrough
|
||||
@@ -975,6 +975,21 @@ swtch:
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *checker) exprConstValue(n *a.Expr) *big.Int {
|
||||
if cv := n.ConstValue(); cv != nil {
|
||||
return cv
|
||||
}
|
||||
if n.Operator() == 0 {
|
||||
if c, ok := q.c.consts[t.QID{0, n.Ident()}]; ok {
|
||||
if cv := c.Value().ConstValue(); cv != nil {
|
||||
n.SetConstValue(cv)
|
||||
return cv
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var comparisonOps = [...]bool{
|
||||
t.IDXBinaryNotEq: true,
|
||||
t.IDXBinaryLessThan: true,
|
||||
|
||||
Reference in new issue
Block a user