]> granicus.if.org Git - vim/commitdiff
patch 8.2.2583: Vim9: cannot compare result of getenv() with null v8.2.2583
authorBram Moolenaar <Bram@vim.org>
Wed, 10 Mar 2021 15:08:26 +0000 (16:08 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 10 Mar 2021 15:08:26 +0000 (16:08 +0100)
Problem:    Vim9: cannot compare result of getenv() with null.
Solution:   Make the return type of getenv() "any". (closes #7943)

src/evalfunc.c
src/testdir/test_vim9_builtin.vim
src/version.c

index bee76c6eafcba48b343f22ff21acb99c29ad2bdc..29bbe8ab879afab04b9b275e1f9fb160ad9026f7 100644 (file)
@@ -1021,7 +1021,7 @@ static funcentry_T global_functions[] =
     {"getcwd",         0, 2, FEARG_1,      NULL,
                        ret_string,         f_getcwd},
     {"getenv",         1, 1, FEARG_1,      NULL,
-                       ret_string,         f_getenv},
+                       ret_any,            f_getenv},
     {"getfontname",    0, 1, 0,            NULL,
                        ret_string,         f_getfontname},
     {"getfperm",       1, 1, FEARG_1,      NULL,
index 3ee8a620f6fb230212745382b0fb665d0c53e91f..8ec3db14829f1c1976e041172569aa9736f1b65b 100644 (file)
@@ -472,6 +472,19 @@ def Test_getchar()
   getchar(true)->assert_equal(0)
 enddef
 
+def Test_getenv()
+  if getenv('does-not_exist') == ''
+    assert_report('getenv() should return null')
+  endif
+  if getenv('does-not_exist') == null
+  else
+    assert_report('getenv() should return null')
+  endif
+  $SOMEENVVAR = 'some'
+  assert_equal('some', getenv('SOMEENVVAR'))
+  unlet $SOMEENVVAR
+enddef
+
 def Test_getcompletion()
   set wildignore=*.vim,*~
   var l = getcompletion('run', 'file', true)
index 447b6e6e349ce9bc863bb1ace36753ef7499c27f..2dbf24a64f8bdf70672f7310d9f481a212da4c55 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2583,
 /**/
     2582,
 /**/