0
0
mirror of https://github.com/vim/vim.git synced 2025-10-17 07:44:28 -04:00

patch 9.0.1201: assignment with operator doesn't work in object method

Problem:    Assignment with operator doesn't work in object method.
Solution:   Handle loading the object member. (closes #11820)  Add a few more
            tests.
This commit is contained in:
Bram Moolenaar
2023-01-15 15:51:48 +00:00
parent 474f226582
commit 4cae845ce3
3 changed files with 72 additions and 0 deletions

View File

@@ -200,6 +200,25 @@ def Test_class_member_initializer()
v9.CheckScriptSuccess(lines)
enddef
def Test_assignment_with_operator()
var lines =<< trim END
vim9script
class Foo
this.x: number
def Add(n: number)
this.x += n
enddef
endclass
var f = Foo.new(3)
f.Add(17)
assert_equal(20, f.x)
END
v9.CheckScriptSuccess(lines)
enddef
def Test_class_default_new()
var lines =<< trim END
vim9script
@@ -521,6 +540,25 @@ def Test_class_member()
END
v9.CheckScriptSuccess(lines)
# example in the help
lines =<< trim END
vim9script
class OtherThing
this.size: number
static totalSize: number
def new(this.size)
totalSize += this.size
enddef
endclass
assert_equal(0, OtherThing.totalSize)
var to3 = OtherThing.new(3)
assert_equal(3, OtherThing.totalSize)
var to7 = OtherThing.new(7)
assert_equal(10, OtherThing.totalSize)
END
v9.CheckScriptSuccess(lines)
# check shadowing
lines =<< trim END
vim9script
@@ -986,6 +1024,23 @@ def Test_class_extends()
assert_equal('Base class: 42', o.ToString())
END
v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9script
class Base
this.value = 1
def new(init: number)
this.value = number + 1
enddef
endclass
class Child extends Base
def new()
this.new(3)
enddef
endclass
var c = Child.new()
END
v9.CheckScriptFailure(lines, 'E1325: Method not found on class "Child": new(')
enddef
def Test_class_import()