Patch 8.2.2010
Problem:    Vim9: compiling fails for unreachable return statement.
Solution:   Fix it. (closes #7319)
Files:      src/vim9compile.c, src/testdir/test_vim9_disassemble.vim


*** ../vim-8.2.2009/src/vim9compile.c   2020-11-17 19:56:05.534193964 +0100
--- src/vim9compile.c   2020-11-18 16:33:21.735220613 +0100
***************
*** 4694,4714 ****
        if (compile_expr0(&p, cctx) == FAIL)
            return NULL;
  
!       stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
!       if (set_return_type)
!           cctx->ctx_ufunc->uf_ret_type = stack_type;
!       else
        {
!           if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID
!                   && stack_type->tt_type != VAR_VOID
!                   && stack_type->tt_type != VAR_UNKNOWN)
            {
!               emsg(_(e_returning_value_in_function_without_return_type));
!               return NULL;
!           }
!           if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1,
                                                   cctx, FALSE, FALSE) == FAIL)
!               return NULL;
        }
      }
      else
--- 4694,4717 ----
        if (compile_expr0(&p, cctx) == FAIL)
            return NULL;
  
!       if (cctx->ctx_skip != SKIP_YES)
        {
!           stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
!           if (set_return_type)
!               cctx->ctx_ufunc->uf_ret_type = stack_type;
!           else
            {
!               if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID
!                       && stack_type->tt_type != VAR_VOID
!                       && stack_type->tt_type != VAR_UNKNOWN)
!               {
!                   emsg(_(e_returning_value_in_function_without_return_type));
!                   return NULL;
!               }
!               if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1,
                                                   cctx, FALSE, FALSE) == FAIL)
!                   return NULL;
!           }
        }
      }
      else
***************
*** 4725,4732 ****
        // No argument, return zero.
        generate_PUSHNR(cctx, 0);
      }
! 
!     if (generate_instr(cctx, ISN_RETURN) == NULL)
        return NULL;
  
      // "return val | endif" is possible
--- 4728,4734 ----
        // No argument, return zero.
        generate_PUSHNR(cctx, 0);
      }
!     if (cctx->ctx_skip != SKIP_YES && generate_instr(cctx, ISN_RETURN) == 
NULL)
        return NULL;
  
      // "return val | endif" is possible
*** ../vim-8.2.2009/src/testdir/test_vim9_disassemble.vim       2020-11-12 
12:08:47.986254110 +0100
--- src/testdir/test_vim9_disassemble.vim       2020-11-18 16:31:42.479566516 
+0100
***************
*** 749,754 ****
--- 749,757 ----
  enddef
  
  def ReturnInIf(): string
+   if 1 < 0
+     return "maybe"
+   endif
    if g:cond
      return "yes"
    else
***************
*** 759,764 ****
--- 762,770 ----
  def Test_disassemble_return_in_if()
    var instr = execute('disassemble ReturnInIf')
    assert_match('ReturnInIf\_s*' ..
+         'if 1 < 0\_s*' ..
+         '  return "maybe"\_s*' ..
+         'endif\_s*' ..
          'if g:cond\_s*' ..
          '0 LOADG g:cond\_s*' ..
          '1 COND2BOOL\_s*' ..
*** ../vim-8.2.2009/src/version.c       2020-11-18 15:30:04.856375372 +0100
--- src/version.c       2020-11-18 16:34:34.518969534 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2010,
  /**/

-- 
"Time flies like an arrow".  So I put an arrow on my desk, now
awaiting one of these time flies showing up.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202011181536.0AIFaJER076220%40masaka.moolenaar.net.

Raspunde prin e-mail lui