diff src/testdir/test_vim9_import.vim @ 27807:292a6bd86c30 v8.2.4429

patch 8.2.4429: using script-local function from the wrong script Commit: https://github.com/vim/vim/commit/c2f17f7e64bb1bf872dbc6f3b8f0d8751e275287 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Feb 21 13:13:50 2022 +0000 patch 8.2.4429: using script-local function from the wrong script Problem: Using script-local function from the wrong script when using a partial. (Yegappan Lakshmanan) Solution: Include the script ID in the partial name.
author Bram Moolenaar <Bram@vim.org>
date Mon, 21 Feb 2022 14:15:04 +0100
parents 60ac4228a73d
children 6e431b1c51d5
line wrap: on
line diff
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -423,6 +423,46 @@ def Test_import_funcref()
   delete('Xlib.vim')
 enddef
 
+def Test_import_duplicate_function()
+  # Function Hover() exists in both scripts, partial should refer to the right
+  # one.
+  var lines =<< trim END
+      vim9script
+
+      def Hover(d: dict<any>): string
+        return 'found it'
+      enddef
+
+      export def NewLspServer(): dict<any>
+        var d: dict<any> = {}
+        d->extend({hover: function('Hover', [d])})
+        return d
+      enddef
+
+      NewLspServer()
+  END
+  writefile(lines, 'Xserver.vim')
+
+  lines =<< trim END
+      vim9script
+
+      import './Xserver.vim' as server
+
+      export def Hover()
+      enddef
+
+      def AddServer()
+        var d: dict<any> = server.NewLspServer()
+        assert_equal('found it', d.hover())
+      enddef
+      AddServer()
+  END
+  v9.CheckScriptSuccess(lines)
+
+  delete('Xserver.vim')
+enddef
+
+
 def Test_import_fails()
   writefile([], 'Xfoo.vim')
   var lines =<< trim END