mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 08:38:14 +01:00
Make the "true" in "while true { etc }" mandatory.
This commit is contained in:
1 parent
1d3ae23418
commit
23020e7d60
3 files changed
+16
-24
No files matched your search
+2
-2
@@ -283,8 +283,8 @@ func NewField(name t.ID, xType *TypeExpr) *Field {
|
||||
}
|
||||
}
|
||||
|
||||
// While is "while { List1 }" or "while LHS { List1 }":
|
||||
// - LHS: <nil|Expr>
|
||||
// While is "while LHS, List0 { List1 }":
|
||||
// - LHS: <Expr>
|
||||
// - List0: <Assert> asserts
|
||||
// - List1: <*> loop body
|
||||
type While Node
|
||||
|
||||
+8
-8
@@ -70,14 +70,13 @@ func (c *typeChecker) checkStatement(n *a.Node) error {
|
||||
|
||||
case a.KWhile:
|
||||
o := n.While()
|
||||
if cond := o.Condition(); cond != nil {
|
||||
if err := c.checkExpr(cond); err != nil {
|
||||
return err
|
||||
}
|
||||
if !cond.MType().Eq(TypeExprBoolean) {
|
||||
return fmt.Errorf("check: for-loop condition %q, of type %q, does not have a boolean type",
|
||||
cond.String(c.idMap), cond.MType().String(c.idMap))
|
||||
}
|
||||
cond := o.Condition()
|
||||
if err := c.checkExpr(cond); err != nil {
|
||||
return err
|
||||
}
|
||||
if !cond.MType().Eq(TypeExprBoolean) {
|
||||
return fmt.Errorf("check: for-loop condition %q, of type %q, does not have a boolean type",
|
||||
cond.String(c.idMap), cond.MType().String(c.idMap))
|
||||
}
|
||||
for _, m := range o.Asserts() {
|
||||
if err := c.checkAssert(m.Assert()); err != nil {
|
||||
@@ -146,6 +145,7 @@ func (c *typeChecker) checkAssert(n *a.Assert) error {
|
||||
return fmt.Errorf("check: assert condition %q, of type %q, does not have a boolean type",
|
||||
cond.String(c.idMap), cond.MType().String(c.idMap))
|
||||
}
|
||||
// TODO: check that there are no side effects.
|
||||
// TODO: check the actual assertion.
|
||||
return nil
|
||||
}
|
||||
|
||||
+6
-14
@@ -413,20 +413,12 @@ func (p *parser) parseStatement1() (*a.Node, error) {
|
||||
|
||||
case t.IDWhile:
|
||||
p.src = p.src[1:]
|
||||
condition, asserts, err := (*a.Expr)(nil), []*a.Node(nil), error(nil)
|
||||
switch p.peekID() {
|
||||
case t.IDOpenCurly:
|
||||
// No-op.
|
||||
default:
|
||||
condition, err = p.parseExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if p.peekID() != t.IDComma {
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
case t.IDComma:
|
||||
condition, err := p.parseExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
asserts := []*a.Node(nil)
|
||||
if p.peekID() == t.IDComma {
|
||||
p.src = p.src[1:]
|
||||
asserts, err = p.parseList(t.IDOpenCurly, (*parser).parseAssertNode)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user