0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

81 Commits

Author SHA1 Message Date
Yegappan Lakshmanan
1db1514365
patch 9.0.1914: Vim9: few issues when accessing object members
Problem:  Vim9: few issues when accessing object members
Solution: When calling an object method, check for null object.
          Accessing a Dict object member doesn't work.

closes: #13119
closes: #13123
closes: #13124

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-19 20:36:02 +02:00
Ernie Rael
3da696db6a
patch 9.0.1911: Vim9: segfault with null object and instanceof()
Problem:  Vim9: segfault with null object and instanceof()
Solution: return early

closes: #13121

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Ernie Rael <errael@raelity.com>
2023-09-19 20:14:18 +02:00
Yegappan Lakshmanan
00cd18222e
patch 9.0.1909: Vim9: problem calling class method from other class
Problem:  Vim9: problem calling class method from other class
Solution: Fix this problem, fix readonly object access, update error
          messages.

Calling a class method from another method without the class name prefix
doesn't work properly.

A readonly object variable is modifiable outside the class using a
nested object assignment.

Remove the unused E1338 error message.

Update error messages.

closes: #13116

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-18 19:56:49 +02:00
Yegappan Lakshmanan
92d9ee5f4c
patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Problem:  Vim9: Interfaces should not support class methods and
          variables
Solution: Make sure interface follow the interface specification

Vim9 interface changes to follow the new interface specification:

1) An interface can have only read-only and read-write instance
   variables.
2) An interface can have only public instance methods.
3) An interface cannot have class variables and class methods.
4) An interface cannot have private instance variables and private
   instance methods.
5) A interface can extend another interface using "extends". The
   sub-interface gets all the variables and methods in the super
   interface.

That means:
- Interfaces should not support class methods and variables.
- Adjust error numbers and add additional tests.
- Interface methods can be defined in one of the super classes.
- Interface variables can be defined in one of the super classes.
  and instance variables can be repeated in sub interfaces.
- Check the class variable types with the type in interface.

closes: #13100

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-17 17:03:19 +02:00
Yegappan Lakshmanan
e2deb7e598
patch 9.0.1902: Vim9: Coverity complains about dead code
Problem:  Vim9: Coverity complains about dead code
Solution: Copy only object methods from the super class
          to a subclass when extending a class.  Fix
          Coverity warning.

closes: #13103

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-16 18:05:07 +02:00
Yegappan Lakshmanan
c30a90d9b2
patch 9.0.1898: Vim9: restrict access to static vars
Problem:  Vim9: restrict access to static vars and methods
Solution: Class members are accesible only from the class where they are
          defined.

Based on the #13004 discussion, the following changes are made:

    1) Static variables and methods are accessible only using the class
       name and inside the class where they are defined.
    2) Static variables and methods can be used without the class name in
       the class where they are defined.
    3) Static variables of a super class are not copied to the sub class.
    4) A sub class can declare a class variable with the same name as the
       super class.
    5) When a method or member is found during compilation, use more
       specific error messages.

This aligns the Vim9 class variable/method implementation with the Dart
implementation.

Also while at it, ignore duplicate class and object methods.

The access level of an object method can however be changed in a
subclass.

For the tests, use the new CheckSourceFailure() function instead of the
CheckScriptFailure() function in the tests.

closes: #13086

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-15 20:14:55 +02:00
Ernie Rael
4d00b835c4
patch 9.0.1895: Vim9: finding object method/member is inefficient
Problem:  Vim9: finding method/member is inefficient
Solution: Use lookups

closes: #13073

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Ernie Rael <errael@raelity.com>
2023-09-11 19:57:52 +02:00
Yegappan Lakshmanan
f36bbcd402
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Problem:  Vim9: lookup code for class/object repaeated
Solution: Refactor and make use of lookup functions

closes: #13067

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-10 18:19:06 +02:00
Yegappan Lakshmanan
342f4f626e
patch 9.0.1888: Vim9: Problem trying to invoke class method
Problem:  Vim9: Problem trying to invoke class method
Solution: Lookup the class method insider other classes

closes: #13055

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-09 11:37:23 +02:00
Yegappan Lakshmanan
23c92d93c1
patch 9.0.1887: Vim9: class members are accessible via object
Problem:  Vim9: class members are accessible via object
Solution: Disable class member variable access using an object

Class methods can be accessed only using the class name and cannot be
accessed using an object. To be consistent with this, do the same for
class member variables also. They can be accessed only using the class
name and not using an object.

closes: #13057

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-09 11:33:29 +02:00
Yegappan Lakshmanan
7bcd25cad3
patch 9.0.1885: Vim9: no support for abstract methods
Problem:  Vim9: no support for abstract methods
Solution: Add support for defining abstract methods in an abstract class

closes: #13044
closes: #13046

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-08 19:29:31 +02:00
Yegappan Lakshmanan
cc0bcf4c9f
patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Problem:  Vim9: Calling an interface method using a child object fails
Solution: Search methods of parent class

When a class implementing an interface is extended by another class and
a child class instance is passed to a function that accepts the
interface, calling an interface method doesn't work properly.

closes: #13053

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-08 19:12:03 +02:00
Ernie Rael
cf138d4ea5
patch 9.0.1880: Vim9: Need more tests for inheritance
Problem:  Vim9: Need more tests for inheritance
Solution: Add access tests and fixes.

`inside_class` fix from yegappan. `object_index_from_itf_index` fix
access of member on class extending class implementing interface.

Based on tests from Vim9: Class/Object member variable access control #12979

closes: #13032
related: #12979

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Ernie Rael <errael@raelity.com>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-06 20:45:03 +02:00
Yegappan Lakshmanan
1689e847ff
patch 9.0.1879: Vim9: incorrect duplicate class member detection
Problem:  Vim9: incorrect duplicate class member detection
Solution: Incorrect duplicate class member detection when variable names
          have the same prefix.  Not able to access class member variables
          using an object. Fix coding style issues

closes: #13042

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-06 20:23:23 +02:00
Ernie Rael
18143d3111
patch 9.0.1867: Vim9: access to interface statics possible
Problem:  Vim9: access to interface statics possible
Solution: Prevent direct access to interface statics

closes: #13007

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Ernie Rael <errael@raelity.com>
2023-09-04 22:30:41 +02:00
Yegappan Lakshmanan
e651e110c1
patch 9.0.1862: Vim9 Garbage Collection issues
Problem:  Vim9 Garbage Collection issues
Solution: Class members are garbage collected early leading to
          use-after-free problems.  Handle the garbage
          collection of classes properly.

closes: #13019

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-04 07:51:01 +02:00
Ernie Rael
21d3212361
patch 9.0.1842: Need more accurate profiling
Problem:  Need more accurate profiling
Solution: Improve profiling results

closes: #12192

Reduce overhead of checking if a function should be profiled,
by caching results of checking (which are done with regexp).

Cache uf_hash for uf_name in ufunc_T.

Cache cleared when regexps are changed.

Break at first match for has_profiling lookup.

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Ernie Rael <errael@raelity.com>
2023-09-02 15:09:18 +02:00
Yegappan Lakshmanan
3775f777a6
patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Problem:  Vim9: Cannot modify class member vars from def function
Solution: Add support for modifying class member variables from a def
          function

closes: #12995

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-09-01 22:05:45 +02:00
Ernie Rael
456ae556b4
patch 9.0.1837: Vim9: class_member_type() can be optimized
Problem:  Vim9: class_member_type() can be optimized
Solution: class_member_type() provides more information;
          safe an additional alloc()/free()

closes: #12989

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Ernie Rael <errael@raelity.com>
2023-09-01 18:57:09 +02:00
Yegappan Lakshmanan
eb91e24d5e
patch 9.0.1829: Vim9 missing access-checks for private vars
Problem:  Vim9 missing access-checks for private vars
Solution: Use the proper check for private/readonly variable.  Access
          level for a member cannot be changed in a class implementing an
          interface.  Update the code indentation

closes: #12978

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Co-authored-by: Ernie Rael <errael@raelity.com>
2023-08-31 18:10:46 +02:00
Yegappan Lakshmanan
e3b6c78ddc
patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Problem:  Vim9: no check for duplicate members in extended classes
Solution: Check for duplicate members in extended classes.
          Fix memory leak.

closes: #12948

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-08-29 22:34:36 +02:00
Gianmaria Bajo
4b9777a1df
patch 9.0.1821: Vim9 constructors are always static
Problem:  Vim9 constructors are always static
Solution: make the "static" keyword an error

closes: #12945

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Gianmaria Bajo <mg1979.git@gmail.com>
2023-08-29 22:29:03 +02:00
Yegappan Lakshmanan
2ba9d2e14e
patch 9.0.1814: Vim9 no error on duplicate object member var
Problem:  Vim9 no error on duplicate object member var
Solution: detect duplicate members and error out

closes: #12938

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-08-28 21:26:23 +02:00
Yegappan Lakshmanan
cd7293bf6c
patch 9.0.1804: Vim9: no support for private object methods
Problem:  Vim9: no support for private object methods
Solution: Add support for private object/class methods

closes: #12920

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-08-27 19:18:23 +02:00
Yegappan Lakshmanan
d4e4ecbb37
patch 9.0.1795: Indentation issues
Problem:  Indentation issues
Solution: Fix code indentation issues.

closes: #12906

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-08-27 18:35:45 +02:00
LemonBoy
afe0466fb1
patch 9.0.1786: Vim9: need instanceof() function
Problem:  Vim9: need instanceof() function
Solution: Implement instanceof() builtin

Implemented in the same form as Python's isinstance because it allows
for checking multiple class types at the same time.

closes: #12867

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: LemonBoy <thatlemon@gmail.com>
2023-08-23 21:08:11 +02:00
Yegappan Lakshmanan
618e47d1cd
patch 9.0.1780: Vim9 type not defined during object creation
Problem:  Vim9 type not defined during object creation
Solution: Define type during object creation and not during class
          definition, parse mulit-line member initializers, fix lock
          initialization

If type is not specified for a member, set it during object creation
instead of during class definition.  Add a runtime type check for the
object member initialization expression

Also, while at it, when copying an object or class, make sure the lock
is correctly initialized.

And finally, parse multi-line member initializers correctly.

closes: #11957
closes: #12868
closes: #12869
closes: #12881

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Co-authored-by: LemonBoy <thatlemon@gmail.com>
2023-08-22 21:29:28 +02:00
Yegappan Lakshmanan
6ac1544e13
patch 9.0.1760: vim9 class problem with new() constructor
Problem:  vim9 class problem with new() constructor
Solution: Don't allow a return type for the new() class constructor.

closes: #12863
closes: #12040

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-08-20 18:20:17 +02:00
Yegappan Lakshmanan
4b1cc7906f
patch 9.0.1757: ex_class() function is too long
Problem:  ex_class() function is too long
Solution: refactor it

closes: #12858

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-08-19 22:39:33 +02:00
Christian Brabandt
28ae5a32fd
patch 9.0.1746: vim9class compile error for char/char_u conversion
Problem: vim9class compile error for char/char_u conversion
Solution: Correctly cast to (char *)

Signed-off-by: Christian Brabandt <cb@256bit.org>
2023-08-19 14:10:48 +02:00
LemonBoy
c5d2744c04
patch 9.0.1741: No type checking in interfaces
Problem: No type checking in interfaces
Solution: Implement member type check in vim9 interfaces

Most of the code is a small refactoring to allow the use of a where_T
for signaling the type mismatch, the type checking itself is pretty
simple.

Improve where_T error reports

Let the caller explicitly define the kind of location it's referring to
and free the WT_ARGUMENT enum from its catch-all role.

Implement type checking for interface methods

Follows closely the logic used for type-checking the members.

closes: #12844

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: LemonBoy <thatlemon@gmail.com>
2023-08-19 13:04:53 +02:00
Yegappan Lakshmanan
b102728c20
patch 9.0.1737: Calling a base class method through an extended class fails
Problem: Calling a base class method through an extended class fails
Solution: Create lookup table for member index in the interface to
          to the member class implementing the interface

Create additional tests for Vim9 classes.  Fix unconvered memory leaks
and crashes found by the new tests.

closes: #12848
closes: #12089

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>author
2023-08-19 11:26:42 +02:00
Yegappan Lakshmanan
a456b12011
patch 9.0.1720: Vim9 class using wrong index for overridden method
Problem: Vim9 class using wrong index for overridden method
Solution: Use correct index for overridden method

closes: #12524
closes: #12813

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-08-16 20:14:37 +02:00
Jia-Ju Bai
5b0889b8bf
patch 9.0.1712: missing null check in object_clear()
Problem: missing null check in object_clear()
Solution: Add null check of cl

closes: #12627

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Jia-Ju Bai <baijiaju@buaa.edu.cn>
2023-08-13 20:05:18 +02:00
Yegappan Lakshmanan
74cc13cc40
patch 9.0.1703: Vim9 Calling a method in an extended class fails
Problem: Vim9 Calling a method in an extended class fails
Solution: use method index directly

closes: #12778

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-08-13 17:41:26 +02:00
Yegappan Lakshmanan
57a02ccf4c
patch 9.0.1701: vim9 crash when class member overridden
Problem: vim9 crash when class member overridden
Solution: Use method_count field instead

closes: #12676
closes: #12677

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
2023-08-13 10:19:38 +02:00
Bram Moolenaar
f7ca56f719 patch 9.0.1609: crash when an object indirectly references itself
Problem:    Crash when an object indirectly references itself.
Solution:   Avoid clearing an object while it is already being cleared.
            (closes #12494)
2023-06-05 16:53:25 +01:00
Ernie Rael
114ec813b3 patch 9.0.1605: crash when calling method on super in child constructor
Problem:    Crash when calling method on super in child constructor. (Israel
            Chauca Fuentes)
Solution:   Clear the type list. (Ernie Rael, closes #12489, closes #12471)
2023-06-04 18:11:35 +01:00
h-east
61378a1542 patch 9.0.1466: cannot use an object member name as a method argument
Problem:    Cannot use an object member name as a method argument.
Solution:   Do not give an error for using an object member name for a method
            argument. (Hirohito Higashi, closes #12241, closes #12225)
            Fix line number for other argument error.
2023-04-18 19:07:29 +01:00
Bram Moolenaar
d13dd30240 patch 9.0.1402: crash when using null_class
Problem:    Crash when using null_class.
Solution:   Give an error when trying to use a null class.
2023-03-11 20:56:35 +00:00
=?UTF-8?q?Ola=20S=C3=B6der?=
d8742476d1 patch 9.0.1381: ACCESS_ names have a conflict with on some systems
Problem:    ACCESS_ names have a conflict with on some systems.
Solution:   Rename by prepending VIM_. (Ola Söder, closes #12105)
2023-03-05 13:12:32 +00:00
Bram Moolenaar
83ae6150bf patch 9.0.1355: no error when declaring a class twice
Problem:    No error when declaring a class twice. (Ernie Rael)
Solution:   Pass different flags when declaring the class. (closes #12057)
2023-02-25 19:59:31 +00:00
Bram Moolenaar
b1e32ac0c9 patch 9.0.1334: using tt_member for the class leads to mistakes
Problem:    Using tt_member for the class leads to mistakes.
Solution:   Add a separate tt_class field.
2023-02-21 12:38:51 +00:00
Bram Moolenaar
552bdca781 patch 9.0.1317: crash when using an unset object variable
Problem:    Crash when using an unset object variable.
Solution:   Give an error instead. (closes #12005)
2023-02-17 21:08:50 +00:00
Bram Moolenaar
d0200c8631 patch 9.0.1254: calling a method on an interface does not work
Problem:    Calling a method on an interface does not work.
Solution:   At runtime figure out what method to call. (closes #11901)
2023-01-28 15:19:40 +00:00
Bram Moolenaar
657aea7fc4 patch 9.0.1249: cannot export an abstract class
Problem:    Cannot export an abstract class. (Ernie Rael)
Solution:   Add the EX_EXPORT flag to :abstract. (closes #11884)
2023-01-27 13:16:19 +00:00
Bram Moolenaar
62a6923470 patch 9.0.1240: cannot access a private object member in a lambda
Problem:    Cannot access a private object member in a lambda defined inside
            the class.
Solution:   Go up the context stack to find the class. (closes #11866)
2023-01-24 15:07:04 +00:00
Bram Moolenaar
29ac5df37b patch 9.0.1209: getting interface member does not always work
Problem:    Getting interface member does not always work.
Solution:   Convert the index on the interface to the index on the object.
            (closes #11825)
2023-01-16 19:43:47 +00:00
Bram Moolenaar
ae3205aa55 patch 9.0.1205: crash when handling class that extends another class
Problem:    Crash when handling class that extends another class with more
            than one object members.
Solution:   Correct pointer computations. (closes #11824)
2023-01-15 20:49:00 +00:00
Bram Moolenaar
24a8d06d7f patch 9.0.1198: abstract class not supported yet
Problem:    Abstract class not supported yet.
Solution:   Implement abstract class and add tests.
2023-01-14 13:12:06 +00:00