scope: break and continue affect the nearest do/end
authorJean Privat <jean@pryen.org>
Thu, 7 Nov 2013 04:19:12 +0000 (23:19 -0500)
committerJean Privat <jean@pryen.org>
Thu, 7 Nov 2013 04:19:12 +0000 (23:19 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/scope.nit
tests/base_label_do.nit
tests/sav/base_label_do_alt4.res [new file with mode: 0644]
tests/sav/base_label_do_alt8.res [new file with mode: 0644]
tests/sav/nitc/base_label_do_alt8.res [new file with mode: 0644]

index 2805556..a3772dd 100644 (file)
@@ -148,7 +148,6 @@ private class ScopeVisitor
        # Display an error on toolcontext if a label with the same name is masked.
        private fun make_escape_mark(nlabel: nullable ALabel, for_loop: Bool): EscapeMark
        do
-               assert named_or_for_loop: nlabel != null or for_loop
                var name: nullable String
                if nlabel != null then
                        name = nlabel.n_id.text
@@ -181,7 +180,7 @@ private class ScopeVisitor
                else
                        for scope in scopes do
                                var res = scope.escapemark
-                               if res != null and res.for_loop then
+                               if res != null then
                                        return res
                                end
                        end
@@ -311,9 +310,7 @@ redef class ADoExpr
        var escapemark: nullable EscapeMark
        redef fun accept_scope_visitor(v)
        do
-               if n_label != null then
-                       self.escapemark = v.make_escape_mark(n_label, false)
-               end
+               self.escapemark = v.make_escape_mark(n_label, false)
                v.enter_visit_block(n_block, self.escapemark)
        end
 end
index c337093..75dc4af 100644 (file)
@@ -30,11 +30,11 @@ do
                #alt3#break label l4
                #alt4#break
                #alt5#continue label l1
+               #alt8#continue
                end
                if maybe then break label l1
                4.output
-       end label l2#alt6#
-       #alt6#end label l1
+       end label l2#alt6# end label l1
        5.output
 end label l1
 6.output
diff --git a/tests/sav/base_label_do_alt4.res b/tests/sav/base_label_do_alt4.res
new file mode 100644 (file)
index 0000000..150a5fb
--- /dev/null
@@ -0,0 +1,5 @@
+1
+2
+3
+5
+6
diff --git a/tests/sav/base_label_do_alt8.res b/tests/sav/base_label_do_alt8.res
new file mode 100644 (file)
index 0000000..e9683f9
--- /dev/null
@@ -0,0 +1 @@
+alt/base_label_do_alt8.nit:33,3--10: Error: cannot 'continue', only 'break'.
diff --git a/tests/sav/nitc/base_label_do_alt8.res b/tests/sav/nitc/base_label_do_alt8.res
new file mode 100644 (file)
index 0000000..027d35e
--- /dev/null
@@ -0,0 +1 @@
+alt/base_label_do_alt8.nit:33,3--10: Syntax Error: 'continue' statment outside block.