]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1556: Vim9: error for missing "return" after "throw" v9.0.1556
authorBram Moolenaar <Bram@vim.org>
Sun, 14 May 2023 18:59:59 +0000 (19:59 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 14 May 2023 18:59:59 +0000 (19:59 +0100)
Problem:    Vim9: error for missing "return" after "throw".
Solution:   Set had_return flag for "throw". (closes #12262)

src/testdir/test_vim9_func.vim
src/version.c
src/vim9compile.c

index 2965afac8fa3bd4e600c669e2c21100a1a06853f..ffb8de48dd0b0645ce7694bfa1782a1f0cef2020 100644 (file)
@@ -488,6 +488,19 @@ def Test_missing_return()
                    'enddef'], 'E1095:')
 enddef
 
+def Test_not_missing_return()
+  var lines =<< trim END
+      def Funky(): number
+        if false
+          return 0
+        endif
+        throw 'Error'
+      enddef
+      defcompile
+  END
+  v9.CheckScriptSuccess(lines)
+enddef
+
 def Test_return_bool()
   var lines =<< trim END
       vim9script
index 292f2285f842e44afab329fa52d4f17803e2a40a..c0c1ca0d9385eb723739ba84345d502d3472e7b3 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1556,
 /**/
     1555,
 /**/
index 477f5eed7e71977011013658a9f2bcb1d80467f5..b894c6f29f18eb9475d3bf74263d2dfa4655d20b 100644 (file)
@@ -3611,6 +3611,7 @@ compile_def_function(
                    break;
            case CMD_throw:
                    line = compile_throw(p, &cctx);
+                   cctx.ctx_had_return = TRUE;
                    break;
 
            case CMD_eval: