scope: the `else` of the assert is a scoped block
[nit.git] / src / semantize / scope.nit
index ad6bcd8..a69c57a 100644 (file)
@@ -20,6 +20,7 @@ module scope
 import phase
 
 redef class ToolContext
+       # Run `APropdef::do_scope` on each propdef.
        var scope_phase: Phase = new ScopePhase(self, null)
 end
 
@@ -98,7 +99,7 @@ private class ScopeVisitor
                var name = variable.name
                var found = search_variable(name)
                if found != null then
-                       self.error(node, "Error: A variable named `{name}' already exists")
+                       self.error(node, "Error: a variable named `{name}` already exists.")
                        return false
                end
                scopes.first.variables[name] = variable
@@ -159,14 +160,14 @@ private class ScopeVisitor
                        if nid == null then
                                var res = search_label("")
                                if res != null then
-                                       self.error(nlabel, "Syntax error: anonymous label already defined.")
+                                       self.error(nlabel, "Syntax Error: anonymous label already defined.")
                                end
                                name = ""
                        else
                                name = nid.text
                                var found = self.search_label(name)
                                if found != null then
-                                       self.error(nlabel, "Syntax error: label {name} already defined.")
+                                       self.error(nlabel, "Syntax Error: label `{name}` already defined.")
                                end
                        end
                else
@@ -189,7 +190,7 @@ private class ScopeVisitor
                        if nid == null then
                                var res = search_label("")
                                if res == null then
-                                       self.error(nlabel, "Syntax error: invalid anonymous label.")
+                                       self.error(nlabel, "Syntax Error: invalid anonymous label.")
                                        return null
                                end
                                return res
@@ -197,7 +198,7 @@ private class ScopeVisitor
                        var name = nid.text
                        var res = search_label(name)
                        if res == null then
-                               self.error(nlabel, "Syntax error: invalid label {name}.")
+                               self.error(nlabel, "Syntax Error: invalid label `{name}`.")
                                return null
                        end
                        return res
@@ -208,7 +209,7 @@ private class ScopeVisitor
                                        return res
                                end
                        end
-                       self.error(node, "Syntax Error: 'break' statement outside block.")
+                       self.error(node, "Syntax Error: `break` statement outside block.")
                        return null
                end
        end
@@ -410,6 +411,32 @@ redef class AForExpr
        end
 end
 
+redef class AWithExpr
+       # The break escape mark associated with the 'with'
+       var break_mark: nullable EscapeMark
+
+       redef fun accept_scope_visitor(v)
+       do
+               v.scopes.unshift(new Scope)
+
+               var escapemark = v.make_escape_mark(n_label, true)
+               self.break_mark = escapemark
+
+               v.enter_visit(n_expr)
+               v.enter_visit_block(n_block, escapemark)
+
+               v.shift_scope
+       end
+end
+
+redef class AAssertExpr
+       redef fun accept_scope_visitor(v)
+       do
+               v.enter_visit(n_expr)
+               v.enter_visit_block(n_else, null)
+       end
+end
+
 redef class AVarFormExpr
        # The associated variable
        var variable: nullable Variable
@@ -424,7 +451,7 @@ redef class ACallFormExpr
                        if variable != null then
                                var n: AExpr
                                if not n_args.n_exprs.is_empty or n_args isa AParExprs then
-                                       v.error(self, "Error: {name} is variable, not a function.")
+                                       v.error(self, "Error: `{name}` is a variable, not a method.")
                                        return
                                end
                                n = variable_create(variable)