Merge: Check missing return in attributes with a block
authorJean Privat <jean@pryen.org>
Wed, 21 Jan 2015 02:39:30 +0000 (09:39 +0700)
committerJean Privat <jean@pryen.org>
Wed, 21 Jan 2015 02:39:30 +0000 (09:39 +0700)
Fixes #1103

Pull-Request: #1114
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

src/semantize/typing.nit
tests/base_attr_init_val_block.nit
tests/sav/base_attr_init_val_block_alt1.res [new file with mode: 0644]
tests/sav/base_attr_init_val_block_alt2.res [new file with mode: 0644]

index 8fb3852..343edbd 100644 (file)
@@ -609,6 +609,10 @@ redef class AAttrPropdef
                var nblock = self.n_block
                if nblock != null then
                        v.visit_stmt(nblock)
+                       if not nblock.after_flow_context.is_unreachable then
+                               # We reach the end of the init without having a return, it is bad
+                               v.error(self, "Control error: Reached end of block (a 'return' with a value was expected).")
+                       end
                end
        end
 end
index 6d2badc..fdafa3d 100644 (file)
@@ -24,7 +24,7 @@ class A
                2.output
                var res = a
                if res == 10 then res = 20
-               return res
+               return res #alt1# return #alt2#
        end
 end
 
diff --git a/tests/sav/base_attr_init_val_block_alt1.res b/tests/sav/base_attr_init_val_block_alt1.res
new file mode 100644 (file)
index 0000000..e50539b
--- /dev/null
@@ -0,0 +1 @@
+alt/base_attr_init_val_block_alt1.nit:27,3--8: Error: Return without value in a function.
diff --git a/tests/sav/base_attr_init_val_block_alt2.res b/tests/sav/base_attr_init_val_block_alt2.res
new file mode 100644 (file)
index 0000000..8545480
--- /dev/null
@@ -0,0 +1 @@
+alt/base_attr_init_val_block_alt2.nit:23,6: Control error: Reached end of block (a 'return' with a value was expected).