comparison src/errors.h @ 33260:aba1fa2b7d1e v9.0.1898

patch 9.0.1898: Vim9: restrict access to static vars Commit: https://github.com/vim/vim/commit/c30a90d9b2c029f794cea502f6b824f71e4876dd Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Fri Sep 15 20:14:55 2023 +0200 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>
author Christian Brabandt <cb@256bit.org>
date Fri, 15 Sep 2023 20:30:05 +0200
parents def9fc5c92d1
children b5ed566262d3
comparison
equal deleted inserted replaced
33259:cf3186a6807f 33260:aba1fa2b7d1e
3409 INIT(= N_("E1331: Public must be followed by \"this\" or \"static\"")); 3409 INIT(= N_("E1331: Public must be followed by \"this\" or \"static\""));
3410 EXTERN char e_public_member_name_cannot_start_with_underscore_str[] 3410 EXTERN char e_public_member_name_cannot_start_with_underscore_str[]
3411 INIT(= N_("E1332: Public member name cannot start with underscore: %s")); 3411 INIT(= N_("E1332: Public member name cannot start with underscore: %s"));
3412 EXTERN char e_cannot_access_private_member_str[] 3412 EXTERN char e_cannot_access_private_member_str[]
3413 INIT(= N_("E1333: Cannot access private member: %s")); 3413 INIT(= N_("E1333: Cannot access private member: %s"));
3414 EXTERN char e_object_member_not_found_str[]
3415 INIT(= N_("E1334: Object member not found: %s"));
3416 EXTERN char e_member_is_not_writable_str[] 3414 EXTERN char e_member_is_not_writable_str[]
3417 INIT(= N_("E1335: Member is not writable: %s")); 3415 INIT(= N_("E1335: Member is not writable: %s"));
3418 #endif 3416 #endif
3419 EXTERN char e_internal_error_shortmess_too_long[] 3417 EXTERN char e_internal_error_shortmess_too_long[]
3420 INIT(= "E1336: Internal error: shortmess too long"); 3418 INIT(= "E1336: Internal error: shortmess too long");
3421 #ifdef FEAT_EVAL 3419 #ifdef FEAT_EVAL
3422 EXTERN char e_class_member_not_found_str[] 3420 EXTERN char e_class_member_str_not_found_in_class_str[]
3423 INIT(= N_("E1337: Class member not found: %s")); 3421 INIT(= N_("E1337: Class member \"%s\" not found in class \"%s\""));
3424 EXTERN char e_member_not_found_on_class_str_str[] 3422 EXTERN char e_member_not_found_on_class_str_str[]
3425 INIT(= N_("E1338: Member not found on class \"%s\": %s")); 3423 INIT(= N_("E1338: Member not found on class \"%s\": %s"));
3426 #endif 3424 #endif
3427 #ifdef FEAT_PROP_POPUP 3425 #ifdef FEAT_PROP_POPUP
3428 EXTERN char e_cannot_add_textprop_with_text_after_using_textprop_with_negative_id[] 3426 EXTERN char e_cannot_add_textprop_with_text_after_using_textprop_with_negative_id[]
3486 INIT(= N_("E1365: Cannot use a return type with the \"new\" function")); 3484 INIT(= N_("E1365: Cannot use a return type with the \"new\" function"));
3487 EXTERN char e_cannot_access_private_method_str[] 3485 EXTERN char e_cannot_access_private_method_str[]
3488 INIT(= N_("E1366: Cannot access private method: %s")); 3486 INIT(= N_("E1366: Cannot access private method: %s"));
3489 EXTERN char e_member_str_of_interface_str_has_different_access[] 3487 EXTERN char e_member_str_of_interface_str_has_different_access[]
3490 INIT(= N_("E1367: Access level of member \"%s\" of interface \"%s\" is different")); 3488 INIT(= N_("E1367: Access level of member \"%s\" of interface \"%s\" is different"));
3491
3492 EXTERN char e_static_cannot_be_followed_by_this[] 3489 EXTERN char e_static_cannot_be_followed_by_this[]
3493 INIT(= N_("E1368: Static cannot be followed by \"this\" in a member name")); 3490 INIT(= N_("E1368: Static cannot be followed by \"this\" in a member name"));
3494 EXTERN char e_duplicate_member_str[] 3491 EXTERN char e_duplicate_member_str[]
3495 INIT(= N_("E1369: Duplicate member: %s")); 3492 INIT(= N_("E1369: Duplicate member: %s"));
3496 EXTERN char e_cannot_define_new_function_as_static[] 3493 EXTERN char e_cannot_define_new_function_as_static[]
3499 INIT(= N_("E1371: Abstract must be followed by \"def\" or \"static\"")); 3496 INIT(= N_("E1371: Abstract must be followed by \"def\" or \"static\""));
3500 EXTERN char e_abstract_method_in_concrete_class[] 3497 EXTERN char e_abstract_method_in_concrete_class[]
3501 INIT(= N_("E1372: Abstract method \"%s\" cannot be defined in a concrete class")); 3498 INIT(= N_("E1372: Abstract method \"%s\" cannot be defined in a concrete class"));
3502 EXTERN char e_abstract_method_str_not_found[] 3499 EXTERN char e_abstract_method_str_not_found[]
3503 INIT(= N_("E1373: Abstract method \"%s\" is not implemented")); 3500 INIT(= N_("E1373: Abstract method \"%s\" is not implemented"));
3501 EXTERN char e_class_member_str_accessible_only_inside_class_str[]
3502 INIT(= N_("E1374: Class member \"%s\" accessible only inside class \"%s\""));
3503 EXTERN char e_class_member_str_accessible_only_using_class_str[]
3504 INIT(= N_("E1375: Class member \"%s\" accessible only using class \"%s\""));
3505 EXTERN char e_object_member_str_accessible_only_using_object_str[]
3506 INIT(= N_("E1376: Object member \"%s\" accessible only using class \"%s\" object"));
3507 EXTERN char e_static_member_not_supported_in_interface[]
3508 INIT(= N_("E1377: Static member is not supported in an interface"));
3509 EXTERN char e_method_str_of_class_str_has_different_access[]
3510 INIT(= N_("E1378: Access level of method \"%s\" is different in class \"%s\""));
3504 EXTERN char e_cannot_mix_positional_and_non_positional_str[] 3511 EXTERN char e_cannot_mix_positional_and_non_positional_str[]
3505 INIT(= N_("E1400: Cannot mix positional and non-positional arguments: %s")); 3512 INIT(= N_("E1400: Cannot mix positional and non-positional arguments: %s"));
3506 EXTERN char e_fmt_arg_nr_unused_str[] 3513 EXTERN char e_fmt_arg_nr_unused_str[]
3507 INIT(= N_("E1401: format argument %d unused in $-style format: %s")); 3514 INIT(= N_("E1401: format argument %d unused in $-style format: %s"));
3508 EXTERN char e_positional_num_field_spec_reused_str_str[] 3515 EXTERN char e_positional_num_field_spec_reused_str_str[]
3519 INIT(= N_("E1407: Method \"%s\": type mismatch, expected %s but got %s")); 3526 INIT(= N_("E1407: Method \"%s\": type mismatch, expected %s but got %s"));
3520 EXTERN char e_aptypes_is_null_nr_str[] 3527 EXTERN char e_aptypes_is_null_nr_str[]
3521 INIT(= "E1408: Internal error: ap_types or ap_types[idx] is NULL: %d: %s"); 3528 INIT(= "E1408: Internal error: ap_types or ap_types[idx] is NULL: %d: %s");
3522 EXTERN char e_interface_static_direct_access_str[] 3529 EXTERN char e_interface_static_direct_access_str[]
3523 INIT(= N_("E1409: Cannot directly access interface \"%s\" static member \"%s\"")); 3530 INIT(= N_("E1409: Cannot directly access interface \"%s\" static member \"%s\""));
3524 // E1371 - E1399 unused 3531 // E1376 - E1399 unused