patch 9.0.1959: Vim9: methods parameters and types are covariant

Problem:  Vim9: methods parameters and types are covariant
Solution: Support contra-variant type check for object method arguments
          (similar to Dart).

closes: #12965
closes: #13221

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
Yegappan Lakshmanan
2023-09-29 22:50:02 +02:00
committed by Christian Brabandt
parent 900894b09a
commit f3b68d4759
7 changed files with 145 additions and 27 deletions

View File

@ -530,6 +530,10 @@ If the type of a variable is not explicitly specified in a class, then it is
set to "any" during class definition. When an object is instantiated from the
class, then the type of the variable is set.
The following reserved keyword names cannot be used as an object or class
variable name: "super", "this", "true", "false", "null", "null_blob",
"null_dict", "null_function", "null_list", "null_partial", "null_string",
"null_channel" and "null_job".
Extending a class ~
*extends*
@ -543,9 +547,11 @@ Object variables from the base class are all taken over by the child class. It
is not possible to override them (unlike some other languages).
*E1356* *E1357* *E1358*
Object methods of the base class can be overruled. The signature (arguments,
argument types and return type) must be exactly the same. The method of the
base class can be called by prefixing "super.".
Object methods of the base class can be overruled. The number of arguments
must be exactly the same. The method argument type can be a contra-variant
type of the base class method argument type. The method return value type can
be a covariant type of the base class method return value type. The method of
the base class can be called by prefixing "super.".
*E1377*
The access level of a method (public or private) in a child class should be