summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics/missing-return.slang
diff options
context:
space:
mode:
Diffstat (limited to 'tests/diagnostics/missing-return.slang')
-rw-r--r--tests/diagnostics/missing-return.slang58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/diagnostics/missing-return.slang b/tests/diagnostics/missing-return.slang
new file mode 100644
index 000000000..83f5f9dc1
--- /dev/null
+++ b/tests/diagnostics/missing-return.slang
@@ -0,0 +1,58 @@
+// missing-return.slang
+
+//TEST:SIMPLE:
+
+// Non-`void` function that fails to return
+
+int bad(int a, int b)
+{
+ int result = a + b;
+
+ // forgot `return` here
+}
+
+int alsoBad(int a, int b)
+{
+ if(a > b)
+ {
+ return a + b;
+ }
+
+ // forgot `return` here
+}
+
+int okay(int a, int b)
+{
+ int tmp = a;
+ for(;;)
+ {
+ if(a > b)
+ return tmp;
+
+ a = b;
+ b = tmp;
+ tmp = a + b;
+ }
+
+ // Lack of `return` here is not
+ // a problem, because we can never
+ // actually get here
+}
+
+int alsoOkay(int a, int b)
+{
+ int tmp = a;
+ while(true)
+ {
+ if(a > b)
+ return tmp;
+
+ a = b;
+ b = tmp;
+ tmp = a + b;
+ }
+
+ // Lack of `return` here is not
+ // a problem, because we can never
+ // actually get here
+} \ No newline at end of file