comparison src/vim9class.c @ 33343:41b50abddeea v9.0.1935

patch 9.0.1935: Vim9: not consistent error messages Commit: https://github.com/vim/vim/commit/7fe8f43f49f4fa6f024d0e0ea76d3df5b62a0879 Author: RestorerZ <restorer@mail2k.ru> Date: Sun Sep 24 23:21:24 2023 +0200 patch 9.0.1935: Vim9: not consistent error messages Problem: Vim9: not consistent error messages Solution: Make error messages more consistent. Use "variable" for (object/class) member closes: #13155 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: RestorerZ <restorer@mail2k.ru>
author Christian Brabandt <cb@256bit.org>
date Sun, 24 Sep 2023 23:30:06 +0200
parents 4e531adb3fac
children 3e9a91624b40
comparison
equal deleted inserted replaced
33342:bc1076074f49 33343:41b50abddeea
77 char_u **init_expr) 77 char_u **init_expr)
78 { 78 {
79 *varname_end = to_name_end(varname, FALSE); 79 *varname_end = to_name_end(varname, FALSE);
80 if (*varname == '_' && has_public) 80 if (*varname == '_' && has_public)
81 { 81 {
82 semsg(_(e_public_member_name_cannot_start_with_underscore_str), line); 82 semsg(_(e_public_variable_name_cannot_start_with_underscore_str), line);
83 return FAIL; 83 return FAIL;
84 } 84 }
85 85
86 char_u *colon = skipwhite(*varname_end); 86 char_u *colon = skipwhite(*varname_end);
87 char_u *type_arg = colon; 87 char_u *type_arg = colon;
111 return FAIL; 111 return FAIL;
112 } 112 }
113 113
114 if (init_expr == NULL && *init_arg == '=') 114 if (init_expr == NULL && *init_arg == '=')
115 { 115 {
116 emsg(_(e_cannot_initialize_member_in_interface)); 116 emsg(_(e_cannot_initialize_variable_in_interface));
117 return FAIL; 117 return FAIL;
118 } 118 }
119 119
120 if (*init_arg == '=') 120 if (*init_arg == '=')
121 { 121 {
424 ocmember_T *p_m = p_members + p_i; 424 ocmember_T *p_m = p_members + p_i;
425 char_u *qstr = (*p_m->ocm_name == '_') 425 char_u *qstr = (*p_m->ocm_name == '_')
426 ? p_m->ocm_name + 1 : p_m->ocm_name; 426 ? p_m->ocm_name + 1 : p_m->ocm_name;
427 if (STRCMP(pstr, qstr) == 0) 427 if (STRCMP(pstr, qstr) == 0)
428 { 428 {
429 semsg(_(e_duplicate_member_str), c_m->ocm_name); 429 semsg(_(e_duplicate_variable_str), c_m->ocm_name);
430 return FALSE; 430 return FALSE;
431 } 431 }
432 } 432 }
433 433
434 p_cl = p_cl->class_extends; 434 p_cl = p_cl->class_extends;
584 continue; 584 continue;
585 585
586 // Ensure the access type is same 586 // Ensure the access type is same
587 if (if_var->ocm_access != m->ocm_access) 587 if (if_var->ocm_access != m->ocm_access)
588 { 588 {
589 semsg(_(e_member_str_of_interface_str_has_different_access), 589 semsg(_(e_variable_str_of_interface_str_has_different_access),
590 if_var->ocm_name, intf_class_name); 590 if_var->ocm_name, intf_class_name);
591 return FALSE; 591 return FALSE;
592 } 592 }
593 593
594 // Ensure the type is matching. 594 // Ensure the type is matching.
660 for (int if_i = 0; if_i < if_count; ++if_i) 660 for (int if_i = 0; if_i < if_count; ++if_i)
661 { 661 {
662 if (!intf_variable_present(intf_class_name, &if_ms[if_i], 662 if (!intf_variable_present(intf_class_name, &if_ms[if_i],
663 is_class_var, cl_ms, cl_count, extends_cl)) 663 is_class_var, cl_ms, cl_count, extends_cl))
664 { 664 {
665 semsg(_(e_member_str_of_interface_str_not_implemented), 665 semsg(_(e_variable_str_of_interface_str_not_implemented),
666 if_ms[if_i].ocm_name, intf_class_name); 666 if_ms[if_i].ocm_name, intf_class_name);
667 return FALSE; 667 return FALSE;
668 } 668 }
669 } 669 }
670 } 670 }
906 { 906 {
907 ocmember_T *m = ((ocmember_T *)mgap->ga_data) + i; 907 ocmember_T *m = ((ocmember_T *)mgap->ga_data) + i;
908 char_u *qstr = *m->ocm_name == '_' ? m->ocm_name + 1 : m->ocm_name; 908 char_u *qstr = *m->ocm_name == '_' ? m->ocm_name + 1 : m->ocm_name;
909 if (STRCMP(pstr, qstr) == 0) 909 if (STRCMP(pstr, qstr) == 0)
910 { 910 {
911 semsg(_(e_duplicate_member_str), name); 911 semsg(_(e_duplicate_variable_str), name);
912 dup = TRUE; 912 dup = TRUE;
913 break; 913 break;
914 } 914 }
915 } 915 }
916 916
955 is_valid_constructor(ufunc_T *uf, int is_abstract, int has_static) 955 is_valid_constructor(ufunc_T *uf, int is_abstract, int has_static)
956 { 956 {
957 // Constructors are not allowed in abstract classes. 957 // Constructors are not allowed in abstract classes.
958 if (is_abstract) 958 if (is_abstract)
959 { 959 {
960 emsg(_(e_cannot_define_new_function_in_abstract_class)); 960 emsg(_(e_cannot_define_new_method_in_abstract_class));
961 return FALSE; 961 return FALSE;
962 } 962 }
963 // A constructor is always static, no need to define it so. 963 // A constructor is always static, no need to define it so.
964 if (has_static) 964 if (has_static)
965 { 965 {
966 emsg(_(e_cannot_define_new_function_as_static)); 966 emsg(_(e_cannot_define_new_method_as_static));
967 return FALSE; 967 return FALSE;
968 } 968 }
969 // A return type should not be specified for the new() 969 // A return type should not be specified for the new()
970 // constructor method. 970 // constructor method.
971 if (uf->uf_ret_type->tt_type != VAR_VOID) 971 if (uf->uf_ret_type->tt_type != VAR_VOID)
972 { 972 {
973 emsg(_(e_cannot_use_a_return_type_with_new)); 973 emsg(_(e_cannot_use_a_return_type_with_new_method));
974 return FALSE; 974 return FALSE;
975 } 975 }
976 return TRUE; 976 return TRUE;
977 } 977 }
978 978
1606 // "public this.varname" 1606 // "public this.varname"
1607 if (STRNCMP(p, "this", 4) == 0) 1607 if (STRNCMP(p, "this", 4) == 0)
1608 { 1608 {
1609 if (p[4] != '.' || !eval_isnamec1(p[5])) 1609 if (p[4] != '.' || !eval_isnamec1(p[5]))
1610 { 1610 {
1611 semsg(_(e_invalid_object_member_declaration_str), p); 1611 semsg(_(e_invalid_object_variable_declaration_str), p);
1612 break; 1612 break;
1613 } 1613 }
1614 if (has_static) 1614 if (has_static)
1615 { 1615 {
1616 emsg(_(e_static_cannot_be_followed_by_this)); 1616 emsg(_(e_static_cannot_be_followed_by_this));
2072 if (m == NULL) 2072 if (m == NULL)
2073 return FAIL; 2073 return FAIL;
2074 2074
2075 if (*name == '_') 2075 if (*name == '_')
2076 { 2076 {
2077 semsg(_(e_cannot_access_private_member_str), m->ocm_name); 2077 semsg(_(e_cannot_access_private_variable_str), m->ocm_name);
2078 return FAIL; 2078 return FAIL;
2079 } 2079 }
2080 2080
2081 // The object only contains a pointer to the class, the member 2081 // The object only contains a pointer to the class, the member
2082 // values array follows right after that. 2082 // values array follows right after that.
2231 return FAIL; 2231 return FAIL;
2232 } 2232 }
2233 2233
2234 if (*name == '_') 2234 if (*name == '_')
2235 { 2235 {
2236 semsg(_(e_cannot_access_private_member_str), m->ocm_name); 2236 semsg(_(e_cannot_access_private_variable_str), m->ocm_name);
2237 return FAIL; 2237 return FAIL;
2238 } 2238 }
2239 2239
2240 typval_T *tv = &cl->class_members_tv[m_idx]; 2240 typval_T *tv = &cl->class_members_tv[m_idx];
2241 copy_tv(tv, rettv); 2241 copy_tv(tv, rettv);
2768 { 2768 {
2769 // If this is a class method, then give a different error 2769 // If this is a class method, then give a different error
2770 if (*name == '_') 2770 if (*name == '_')
2771 semsg(_(e_cannot_access_private_method_str), method_name); 2771 semsg(_(e_cannot_access_private_method_str), method_name);
2772 else 2772 else
2773 semsg(_(e_class_member_str_accessible_only_using_class_str), 2773 semsg(_(e_class_method_str_accessible_only_using_class_str),
2774 method_name, cl->class_name); 2774 method_name, cl->class_name);
2775 } 2775 }
2776 else if ((v_type == VAR_CLASS) 2776 else if ((v_type == VAR_CLASS)
2777 && (object_method_idx(cl, name, len) >= 0)) 2777 && (object_method_idx(cl, name, len) >= 0))
2778 { 2778 {
2779 // If this is an object method, then give a different error 2779 // If this is an object method, then give a different error
2780 if (*name == '_') 2780 if (*name == '_')
2781 semsg(_(e_cannot_access_private_method_str), method_name); 2781 semsg(_(e_cannot_access_private_method_str), method_name);
2782 else 2782 else
2783 semsg(_(e_object_member_str_accessible_only_using_object_str), 2783 semsg(_(e_object_method_str_accessible_only_using_object_str),
2784 method_name, cl->class_name); 2784 method_name, cl->class_name);
2785 } 2785 }
2786 else 2786 else
2787 semsg(_(e_method_not_found_on_class_str_str), cl->class_name, 2787 semsg(_(e_method_not_found_on_class_str_str), cl->class_name,
2788 method_name); 2788 method_name);
2798 char_u *varname = len ? vim_strnsave(name, len) : vim_strsave(name); 2798 char_u *varname = len ? vim_strnsave(name, len) : vim_strsave(name);
2799 2799
2800 if (v_type == VAR_OBJECT) 2800 if (v_type == VAR_OBJECT)
2801 { 2801 {
2802 if (class_member_idx(cl, name, len) >= 0) 2802 if (class_member_idx(cl, name, len) >= 0)
2803 semsg(_(e_class_member_str_accessible_only_using_class_str), 2803 semsg(_(e_class_variable_str_accessible_only_using_class_str),
2804 varname, cl->class_name); 2804 varname, cl->class_name);
2805 else 2805 else
2806 semsg(_(e_member_not_found_on_object_str_str), cl->class_name, 2806 semsg(_(e_variable_not_found_on_object_str_str), cl->class_name,
2807 varname); 2807 varname);
2808 } 2808 }
2809 else 2809 else
2810 { 2810 {
2811 if (object_member_idx(cl, name, len) >= 0) 2811 if (object_member_idx(cl, name, len) >= 0)
2812 semsg(_(e_object_member_str_accessible_only_using_object_str), 2812 semsg(_(e_object_variable_str_accessible_only_using_object_str),
2813 varname, cl->class_name); 2813 varname, cl->class_name);
2814 else 2814 else
2815 semsg(_(e_class_member_str_not_found_in_class_str), 2815 semsg(_(e_class_variable_str_not_found_in_class_str),
2816 varname, cl->class_name); 2816 varname, cl->class_name);
2817 } 2817 }
2818 vim_free(varname); 2818 vim_free(varname);
2819 } 2819 }
2820 2820