changeset 24083:1765b5b0f08d v8.2.2583

patch 8.2.2583: Vim9: cannot compare result of getenv() with null Commit: https://github.com/vim/vim/commit/7ad67d1150a1e48371d64e2919591c38b80e7cfc Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 10 16:08:26 2021 +0100 patch 8.2.2583: Vim9: cannot compare result of getenv() with null Problem: Vim9: cannot compare result of getenv() with null. Solution: Make the return type of getenv() "any". (closes https://github.com/vim/vim/issues/7943)
author Bram Moolenaar <Bram@vim.org>
date Wed, 10 Mar 2021 16:15:03 +0100
parents 25dfbd338255
children 3865ddb3834a
files src/evalfunc.c src/testdir/test_vim9_builtin.vim src/version.c
diffstat 3 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -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,
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -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)
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2583,
+/**/
     2582,
 /**/
     2581,