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