diff src/testdir/test_vim9_class.vim @ 31590:aee868b9229a v9.0.1127

patch 9.0.1127: no error if function argument shadows class member Commit: https://github.com/vim/vim/commit/6acf757c6a11c0653b0132a17c22983856da5ad6 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 1 19:53:30 2023 +0000 patch 9.0.1127: no error if function argument shadows class member Problem: No error if function argument shadows class member. Solution: Give an error for shadowing a class member.
author Bram Moolenaar <Bram@vim.org>
date Sun, 01 Jan 2023 21:00:03 +0100
parents 8bbc932fbd09
children 9b13b3a63bc0
line wrap: on
line diff
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -367,7 +367,8 @@ def Test_class_object_member_access()
   v9.CheckScriptFailure(lines, 'E1041:')
 enddef
 
-def Test_class_member_access()
+def Test_class_member()
+  # check access rules
   var lines =<< trim END
       vim9script
       class TextPos
@@ -401,6 +402,38 @@ def Test_class_member_access()
       assert_equal(17, TextPos.anybody)
   END
   v9.CheckScriptSuccess(lines)
+
+  # check shadowing
+  lines =<< trim END
+      vim9script
+
+      class Some
+        static count = 0
+        def Method(count: number)
+          echo count
+        enddef
+      endclass
+
+      var s = Some.new()
+      s.Method(7)
+  END
+  v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the class: count')
+
+  lines =<< trim END
+      vim9script
+
+      class Some
+        static count = 0
+        def Method(arg: number)
+          var count = 3
+          echo arg count
+        enddef
+      endclass
+
+      var s = Some.new()
+      s.Method(7)
+  END
+  v9.CheckScriptFailure(lines, 'E1341: Variable already declared in the class: count')
 enddef
 
 def Test_class_function()