mirror of
https://github.com/vim/vim.git
synced 2025-10-21 08:24:06 -04:00
patch 9.1.0850: Vim9: cannot access nested object inside objects
Problem: Vim9: cannot access nested object inside objects (lifepillar, 91khr, mawkish) Solution: Add support for accessing an object member using a "any" variable type (Yegappan Lakshmanan) fixes: #11822 fixes: #12024 fixes: #12196 fixes: #12198 closes: #16029 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
622f6f5b9a
commit
56d45f1b66
@@ -9282,6 +9282,7 @@ o_CTRL-V motion.txt /*o_CTRL-V*
|
||||
o_V motion.txt /*o_V*
|
||||
o_object-select motion.txt /*o_object-select*
|
||||
o_v motion.txt /*o_v*
|
||||
obj-var-type-any vim9class.txt /*obj-var-type-any*
|
||||
object vim9class.txt /*object*
|
||||
object-const-variable vim9class.txt /*object-const-variable*
|
||||
object-empty() vim9class.txt /*object-empty()*
|
||||
|
@@ -1,4 +1,4 @@
|
||||
*vim9class.txt* For Vim version 9.1. Last change: 2024 Apr 13
|
||||
*vim9class.txt* For Vim version 9.1. Last change: 2024 Nov 11
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -873,6 +873,33 @@ Note that the method name must start with "new". If there is no method called
|
||||
"new()" then the default constructor is added, even though there are other
|
||||
constructor methods.
|
||||
|
||||
Using variable type "any" for an Object~
|
||||
*obj-var-type-any*
|
||||
You can use a variable declared with type "any" to hold an object. e.g.
|
||||
>
|
||||
vim9script
|
||||
class A
|
||||
var n = 10
|
||||
def Get(): number
|
||||
return this.n
|
||||
enddef
|
||||
endclass
|
||||
|
||||
def Fn(o: any)
|
||||
echo o.n
|
||||
echo o.Get()
|
||||
enddef
|
||||
|
||||
var a = A.new()
|
||||
Fn(a)
|
||||
<
|
||||
In this example, Vim cannot determine the type of the parameter "o" for
|
||||
function Fn() at compile time. It can be either a |Dict| or an |Object|
|
||||
value. Therefore, at runtime, when the type is known, the object member
|
||||
variable and method are looked up. This process is not efficient, so it is
|
||||
recommended to use a more specific type whenever possible for better
|
||||
efficiency.
|
||||
|
||||
Compiling methods in a Class ~
|
||||
*class-compile*
|
||||
The |:defcompile| command can be used to compile all the class and object
|
||||
|
Reference in New Issue
Block a user