In #13118 (comment) it says
In the current implementation the read-only object variable behaves like a "final" variable.
The following script gives the error
E1335: Member is not writable: inner
While it's true that inner is not writable, the test does not attempt to write to the variable inner. It is writing to the class Inner public variable val.
vim9script
class Inner
public this.val = 13
endclass
class Outer
this.inner = Inner.new()
endclass
var o1 = Outer.new()
o1.inner.var = 11 # <<<<< can't write
No error. The object's variable val is written to.
9.0.1916
ubuntu
No response
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
An example of writing to val when the object reference is final
vim9script
class Inner
public this.val = 13
endclass
final o2 = Inner.new()
o2.val = 11
echo o2.val
def F()
final o = Inner.new()
o.val = 11
echo o.val
enddef
F()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/vim/vim/issues/13130%40github.com.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
correct a couple of bugs
this.inner is not supposed to be publicly writable; once this.inner is set, it is not supposed to be changed from outside the class to reference a different object. Only val is public. I don't see a bug in the test script.
The implementation should treat this.inner as final, but it is treating it as const.
class Outer
this.inner = Inner.new()
endclass
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.![]()
This only fails at script level, works in :def
vim9script
class Inner
public this.val = 13
endclass
class Outer
this.inner: Inner = Inner.new()
endclass
var o1 = Outer.new()
def F()
o1.inner.val = 11 # OK
echo o1.inner.val
enddef
F()
o1.inner.var = 11 # <<<<< can't write
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.![]()
It works fine for me once I correct a couple of bugs
var o1 = Outer.new() o1.inner.var = 11 # <<<<< can't write
-- Christian J. Robinson @.***>
Thanks Christian, I only noticed the change to public this.inner which should not have public. I missed that you caught the var which is supposed to be val.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.![]()
@yegappan This might be the fix, there's the assumption that 'name..' and 'name.=' can't happen when processing an object or class.
diff --git a/src/eval.c b/src/eval.c
--- a/src/eval.c
+++ b/src/eval.c
@@ -1564,6 +1564,9 @@
om->ocm_name);
return NULL;
case VIM_ACCESS_READ:
+ // If [idx] or .key following, read only OK.
+ if (*p == '[' || *p == '.')
+ break;
if ((flags & GLV_READ_ONLY) == 0)
{
semsg(_(e_member_is_not_writable_str),
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.![]()
@yegappan This might be the fix, there's the assumption that 'name..' and 'name.=' can't happen when processing an object or class.
Yes. This looks good to me. I was working on a fix similar to the one below. Can you open a PR
with this change and a test?
diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -1564,6 +1564,9 @@ om->ocm_name); return NULL; case VIM_ACCESS_READ: + // If [idx] or .key following, read only OK. + if (*p == '[' || *p == '.') + break; if ((flags & GLV_READ_ONLY) == 0) { semsg(_(e_member_is_not_writable_str),
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.![]()
Can you open a PR with this change and a test?
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.![]()
Closed #13130 as completed via 98e68c0.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.![]()