Patch 8.2.2290
Problem:    Vim9: unlet of global variable cannot be compiled.
Solution:   Skip over variables that might be defined later. Give an error if
            a subscript is found. (closes #7585)
Files:      src/eval.c, src/vim9compile.c, src/vim.h,
            src/testdir/test_vim9_assign.vim


*** ../vim-8.2.2289/src/eval.c  2021-01-03 19:51:01.396063220 +0100
--- src/eval.c  2021-01-03 20:15:23.658340160 +0100
***************
*** 813,821 ****
      // Clear everything in "lp".
      CLEAR_POINTER(lp);
  
!     if (skip)
      {
!       // When skipping just find the end of the name.
        lp->ll_name = name;
        lp->ll_name_end = find_name_end(name, NULL, NULL,
                                                      FNE_INCL_BR | fne_flags);
--- 813,821 ----
      // Clear everything in "lp".
      CLEAR_POINTER(lp);
  
!     if (skip || (flags & GLV_COMPILING))
      {
!       // When skipping or compiling just find the end of the name.
        lp->ll_name = name;
        lp->ll_name_end = find_name_end(name, NULL, NULL,
                                                      FNE_INCL_BR | fne_flags);
*** ../vim-8.2.2289/src/vim9compile.c   2021-01-03 18:33:09.992382498 +0100
--- src/vim9compile.c   2021-01-03 20:51:54.555536558 +0100
***************
*** 6130,6135 ****
--- 6130,6141 ----
  
        // Normal name.  Only supports g:, w:, t: and b: namespaces.
        *name_end = NUL;
+       if (vim_strchr(p, '.') != NULL || vim_strchr(p, '[') != NULL)
+       {
+           *name_end = cc;
+           goto failed;
+       }
+ 
        if (*p == '$')
            ret = generate_UNLET(cctx, ISN_UNLETENV, p + 1, eap->forceit);
        else if (check_vim9_unlet(p) == FAIL)
***************
*** 6141,6148 ****
--- 6147,6157 ----
        return ret;
      }
  
+ failed:
      // TODO: unlet {list}[idx]
      // TODO: unlet {dict}[key]
+     // complication: {list} can be global while "idx" is local, thus we can't
+     // call ex_unlet().
      emsg("Sorry, :unlet not fully implemented yet");
      return FAIL;
  }
***************
*** 6163,6169 ****
      }
  
      // TODO: this doesn't work for local variables
!     ex_unletlock(eap, p, 0, GLV_NO_AUTOLOAD, compile_unlet, cctx);
      return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd;
  }
  
--- 6172,6179 ----
      }
  
      // TODO: this doesn't work for local variables
!     ex_unletlock(eap, p, 0, GLV_NO_AUTOLOAD | GLV_COMPILING,
!                                                         compile_unlet, cctx);
      return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd;
  }
  
*** ../vim-8.2.2289/src/vim.h   2021-01-01 21:05:51.222773812 +0100
--- src/vim.h   2021-01-03 20:31:55.066552640 +0100
***************
*** 2544,2555 ****
--- 2544,2557 ----
  #define TFN_NO_DEREF  0x08    // do not dereference a Funcref
  #define TFN_READ_ONLY 0x10    // will not change the var
  #define TFN_NO_DECL   0x20    // only used for GLV_NO_DECL
+ #define TFN_COMPILING 0x40    // only used for GLV_COMPILING
  
  // Values for get_lval() flags argument:
  #define GLV_QUIET     TFN_QUIET       // no error messages
  #define GLV_NO_AUTOLOAD       TFN_NO_AUTOLOAD // do not use script autoloading
  #define GLV_READ_ONLY TFN_READ_ONLY   // will not change the var
  #define GLV_NO_DECL   TFN_NO_DECL     // assignment without :var or :let
+ #define GLV_COMPILING TFN_COMPILING   // variable may be defined later
  
  #define DO_NOT_FREE_CNT 99999 // refcount for dict or list that should not
                                // be freed.
*** ../vim-8.2.2289/src/testdir/test_vim9_assign.vim    2021-01-01 
21:05:51.222773812 +0100
--- src/testdir/test_vim9_assign.vim    2021-01-03 20:53:18.415394020 +0100
***************
*** 1340,1345 ****
--- 1340,1354 ----
    assert_false(exists('s:somevar'))
    unlet! s:somevar
  
+   # can compile unlet before variable exists
+   # This doesn't work yet
+   #g:someDict = {key: 'val'}
+   #var k = 'key'
+   #unlet g:someDict[k]
+   #assert_equal({}, g:someDict)
+   #unlet g:someDict
+   #assert_false(exists('g:someDict'))
+ 
    CheckScriptFailure([
     'vim9script',
     'var svar = 123',
*** ../vim-8.2.2289/src/version.c       2021-01-03 19:51:01.400063201 +0100
--- src/version.c       2021-01-03 20:16:35.094059653 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2290,
  /**/

-- 
>From "know your smileys":
 8<}}   Glasses, big nose, beard

 /// Bram Moolenaar -- [email protected] -- 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202101031957.103JvKDf2228265%40masaka.moolenaar.net.

Raspunde prin e-mail lui