patch 9.0.1948: Vim9: object variable "this." should only be used in constructor
Problem: Vim9: object variable "this." should only be used in
constructor
Solution: Disallow to this in normal object methods (other than
constructors)
closes: #13152
closes: #13212
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: h-east <h.east.727@gmail.com>
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index 2fd66c9..c272aab 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -956,6 +956,17 @@
v9.CheckSourceFailure(lines, 'E1013:')
lines =<< trim END
+ vim9script
+
+ class C
+ this.str: string
+ def MethodA(this.str)
+ enddef
+ endclass
+ END
+ v9.CheckSourceFailure(lines, 'E1390: Cannot use an object variable "this.str" except with the "new" method')
+
+ lines =<< trim END
vim9script
class C