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/userfunc.c b/src/userfunc.c
index e0c1d5f..0f487fc 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -320,6 +320,16 @@
++p;
char_u *argend = p;
+ // object variable this. can be used only in a constructor
+ if (STRNCMP(eap->arg, "new", 3) != 0)
+ {
+ c = *argend;
+ *argend = NUL;
+ semsg(_(e_cannot_use_an_object_variable_except_with_the_new_method_str), arg);
+ *argend = c;
+ break;
+ }
+
if (*skipwhite(p) == '=')
{
char_u *defval = skipwhite(skipwhite(p) + 1);