Permalink
Browse files

Detect use of flow control statements outside of a loop - Closes #603

  • Loading branch information...
1 parent d51dc56 commit cee2f308f069597f67bd73b75e4362d9496f2b8a @shamanas shamanas committed Feb 19, 2013
Showing with 11 additions and 2 deletions.
  1. +11 −2 source/rock/middle/FlowControl.ooc
@@ -1,6 +1,6 @@
import ../frontend/Token
-import Statement, Visitor, Node
-import tinker/[Trail, Resolver, Response]
+import Statement, While, Foreach, Visitor, Node
+import tinker/[Trail, Resolver, Response, Errors]
FlowAction: enum {
_break
@@ -37,6 +37,15 @@ FlowControl: class extends Statement {
replace: func (oldie, kiddo: Node) -> Bool { false }
resolve: func (trail: Trail, res: Resolver) -> Response {
+ // Make sure we are either in a while of foreach statement
+ if(trail find(While) == -1 && trail find(Foreach) == -1) {
+ res throwError(InvalidFlowControl new(token, "Invalid use of %s outside of a loop" format(action toString())))
+ }
+
Response OK
}
}
+
+InvalidFlowControl: class extends Error {
+ init: super func ~tokenMessage
+}

0 comments on commit cee2f30

Please sign in to comment.