Source this script:
vim9script class X public this.attr = 42 endclass class Y public this.xobj = X.new() endclass def F(yobj: Y) var xx = yobj.xobj xx.attr += 1 enddef var yy = Y.new() F(yy)
This fails with E1089: Unknown variable: tr += 1. This is a minor issue, as a simple workaround is to just use + instead of +=:
xx.attr = xx.attr + 1
Note that out of a function the assignment with += works:
var xx = X.new() xx.attr += 1 echo xx.attr # OK
and even
var yy = Y.new() yy.xobj.attr += 1 echo yy.xobj.attr # OK
The sourced script should run without errors.
9.0.1454
macOS
Apple Terminal
xterm-256color
ZSH 5.9
No response
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Hm, I haven't looked closely at the vim9 implementation, but here Vim only seems to handle this correctly. Which means, if you use:
var that = yobj.xobj
it starts to work :)
I think, instead of hard-coding the 5 we need this patch here:
diff --git a/src/vim9compile.c b/src/vim9compile.c index 64526aa9d..0f795f799 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -2065,10 +2065,16 @@ compile_load_lhs_with_index(lhs_T *lhs, char_u *var_start, cctx_T *cctx) { if (lhs->lhs_type->tt_type == VAR_OBJECT) { - // "this.value": load "this" object and get the value at index + char_u *dot = vim_strchr(var_start, '.'); + + if (dot == NULL) + return FAIL; + + // "object.value" or "this.value": + // load "this" object and get the value at index // for an object or class member get the type of the member class_T *cl = lhs->lhs_type->tt_class; - type_T *type = class_member_type(cl, var_start + 5, + type_T *type = class_member_type(cl, dot + 1, lhs->lhs_end, &lhs->lhs_member_idx); if (lhs->lhs_member_idx < 0) return FAIL;
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Closed #12263 as completed via 22363c6.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()