Finish syntax analysis for default closure.
authorJean Privat <jean@pryen.org>
Fri, 6 Feb 2009 15:26:27 +0000 (10:26 -0500)
committerJean Privat <jean@pryen.org>
Fri, 6 Feb 2009 15:26:27 +0000 (10:26 -0500)
src/syntax/control_flow.nit
src/syntax/typing.nit

index 11371ac..0903077 100644 (file)
@@ -316,6 +316,30 @@ redef class AVarReassignExpr
        end
 end
 
+redef class AClosureDecl
+       redef meth accept_control_flow(v)
+       do
+               if n_expr != null then
+                       var old_control_flow_ctx = v.control_flow_ctx
+                       v.control_flow_ctx = v.control_flow_ctx.sub
+                       # Register the block
+                       v.control_flow_ctx.base_block = n_expr
+
+                       super
+
+                       if v.control_flow_ctx.unreash == false then
+                               if variable.closure.signature.return_type != null then
+                                       v.error(self, "Control error: Reached end of bloc (a 'continue' with a value was expected).")
+                               else if variable.closure.is_break then
+                                       v.error(self, "Control error: Reached end of break bloc (an 'abort' was expected).")
+                               end
+                       end
+
+                       v.control_flow_ctx = old_control_flow_ctx
+               end
+       end
+end
+
 redef class AClosureDef
 special AControlableBlock
        redef meth accept_control_flow(v)
index 5f49fba..04c1a62 100644 (file)
@@ -298,9 +298,19 @@ redef class PParam
 end
 
 redef class AClosureDecl
-       redef meth after_typing(v)
+       redef meth accept_typing(v)
        do
+               # Register the closure for ClosureCallExpr
                v.variable_ctx.add(variable)
+
+               var old_var_ctx = v.variable_ctx
+               v.variable_ctx = v.variable_ctx.sub
+               v.closure = variable.closure
+
+               super
+
+               v.variable_ctx = old_var_ctx
+               v.closure = null
        end
 end