Simplify control flow and update tests.
authorJean Privat <jean@pryen.org>
Tue, 20 Jan 2009 16:55:09 +0000 (11:55 -0500)
committerJean Privat <jean@pryen.org>
Tue, 20 Jan 2009 16:55:09 +0000 (11:55 -0500)
attr _has_return is not needed since _unreash can do the job.
Also improve the error message if a return is missing.
Tests results are updated to reflect the new error message.

src/syntax/control_flow.nit
tests/sav/base_control_flow_alt1.sav [new file with mode: 0644]
tests/sav/error_fun_ret.sav
tests/sav/error_fun_ret2.sav
tests/sav/error_fun_ret3.sav
tests/sav/error_fun_ret4.sav
tests/sav/error_fun_ret5.sav
tests/sav/error_ref_fun.sav
tests/sav/error_spe_fun.sav

index 0891fe2..86856c8 100644 (file)
@@ -81,9 +81,6 @@ private class ControlFlowContext
        # Previous control flow context if any
        readable attr _prev: ControlFlowContext
 
-       # Is a return met?
-       readable writable attr _has_return: Bool 
-
        # Is a control flow break met? (return, break, continue)
        readable writable attr _unreash: Bool
 
@@ -115,7 +112,6 @@ private class ControlFlowContext
        init with_prev(p: ControlFlowContext)
        do
                _prev = p
-               _has_return = p.has_return
                _unreash = p.unreash
                _already_unreash = p.already_unreash
                _base_block = p.base_block
@@ -143,8 +139,8 @@ redef class AConcreteMethPropdef
        redef meth accept_control_flow(v)
        do
                super
-               if v.control_flow_ctx.has_return == false and method.signature.return_type != null then
-                       v.error(self, "Control error: Reached end of function.")
+               if v.control_flow_ctx.unreash == false and method.signature.return_type != null then
+                       v.error(self, "Control error: Reached end of function (a 'return' with a value was expected).")
                end
        end
 end
@@ -174,7 +170,6 @@ redef class AReturnExpr
        redef meth accept_control_flow(v)
        do
                super
-               v.control_flow_ctx.has_return = true
                v.control_flow_ctx.unreash = true
        end
 end
@@ -217,7 +212,6 @@ redef class AAbortExpr
        redef meth accept_control_flow(v)
        do
                super
-               v.control_flow_ctx.has_return = true
                v.control_flow_ctx.unreash = true
        end
 end
@@ -244,7 +238,6 @@ redef class AIfExpr
                        v.visit(n_else)
 
                        # Merge then and else in the old control_flow
-                       old_control_flow_ctx.has_return = v.control_flow_ctx.has_return and then_control_flow_ctx.has_return
                        old_control_flow_ctx.unreash = v.control_flow_ctx.unreash and then_control_flow_ctx.unreash
 
                        if v.control_flow_ctx.unreash then v.control_flow_ctx = then_control_flow_ctx
diff --git a/tests/sav/base_control_flow_alt1.sav b/tests/sav/base_control_flow_alt1.sav
new file mode 100644 (file)
index 0000000..f08ad05
--- /dev/null
@@ -0,0 +1,2 @@
+alt/base_control_flow_alt1.nit:26,1--30:2: Control error: Reached end of function (a 'return' with a value was expected).
+alt/base_control_flow_alt1.nit:33,1--41:2: Control error: Reached end of function (a 'return' with a value was expected).
index 1dd9cc6..da219e4 100644 (file)
@@ -1 +1 @@
-./error_fun_ret.nit:17,1--14: Control error: Reached end of function.
+./error_fun_ret.nit:17,1--14: Control error: Reached end of function (a 'return' with a value was expected).
index d205076..8143716 100644 (file)
@@ -1 +1 @@
-./error_fun_ret2.nit:17,1--20:10: Control error: Reached end of function.
+./error_fun_ret2.nit:17,1--20:10: Control error: Reached end of function (a 'return' with a value was expected).
index 59a2e19..47c223a 100644 (file)
@@ -1 +1 @@
-./error_fun_ret3.nit:17,1--21:10: Control error: Reached end of function.
+./error_fun_ret3.nit:17,1--21:10: Control error: Reached end of function (a 'return' with a value was expected).
index 8159505..3ad3d28 100644 (file)
@@ -1 +1 @@
-./error_fun_ret4.nit:17,1--21:10: Control error: Reached end of function.
+./error_fun_ret4.nit:17,1--21:10: Control error: Reached end of function (a 'return' with a value was expected).
index c8064bd..41a4c7d 100644 (file)
@@ -1 +1 @@
-./error_fun_ret5.nit:17,1--20:10: Control error: Reached end of function.
+./error_fun_ret5.nit:17,1--20:10: Control error: Reached end of function (a 'return' with a value was expected).
index f389fb0..4018472 100644 (file)
@@ -1 +1 @@
-./error_ref_fun.nit:20,2--13: Control error: Reached end of function.
+./error_ref_fun.nit:20,2--13: Control error: Reached end of function (a 'return' with a value was expected).
index 85fda12..4d47359 100644 (file)
@@ -1 +1 @@
-./error_spe_fun.nit:23,1--15: Control error: Reached end of function.
+./error_spe_fun.nit:23,1--15: Control error: Reached end of function (a 'return' with a value was expected).