Mercurial > vim
comparison src/vim9expr.c @ 33738:2172872dfbcd v9.0.2096
patch 9.0.2096: Vim9: confusing usage of private
Commit: https://github.com/vim/vim/commit/03042a2753e3e6ac971045a8ce256d709214710e
Author: Ernie Rael <errael@raelity.com>
Date: Sat Nov 11 08:53:32 2023 +0100
patch 9.0.2096: Vim9: confusing usage of private
Problem: Vim9: confusing usage of private
Solution: clarify and use protected keyword instead
[vim9class] document `_` as protected instead of private
fixes #13504
closes: #13520
Signed-off-by: Ernie Rael <errael@raelity.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 11 Nov 2023 09:00:06 +0100 |
parents | f126ffc85f7c |
children | 84b93d95a952 |
comparison
equal
deleted
inserted
replaced
33737:f065fe97d07a | 33738:2172872dfbcd |
---|---|
401 ((type->tt_type == VAR_OBJECT | 401 ((type->tt_type == VAR_OBJECT |
402 && !inside_class_hierarchy(cctx, cl)) | 402 && !inside_class_hierarchy(cctx, cl)) |
403 || (type->tt_type == VAR_CLASS | 403 || (type->tt_type == VAR_CLASS |
404 && cctx->ctx_ufunc->uf_class != cl))) | 404 && cctx->ctx_ufunc->uf_class != cl))) |
405 { | 405 { |
406 semsg(_(e_cannot_access_private_method_str), name); | 406 semsg(_(e_cannot_access_protected_method_str), name); |
407 return FAIL; | 407 return FAIL; |
408 } | 408 } |
409 | 409 |
410 // Compile the arguments and call the class function or object method. | 410 // Compile the arguments and call the class function or object method. |
411 // The object method will know that the object is on the stack, just | 411 // The object method will know that the object is on the stack, just |
428 ocmember_T *m = object_member_lookup(cl, name, len, &m_idx); | 428 ocmember_T *m = object_member_lookup(cl, name, len, &m_idx); |
429 if (m_idx >= 0) | 429 if (m_idx >= 0) |
430 { | 430 { |
431 if (*name == '_' && !inside_class(cctx, cl)) | 431 if (*name == '_' && !inside_class(cctx, cl)) |
432 { | 432 { |
433 emsg_var_cl_define(e_cannot_access_private_variable_str, | 433 emsg_var_cl_define(e_cannot_access_protected_variable_str, |
434 m->ocm_name, 0, cl); | 434 m->ocm_name, 0, cl); |
435 return FAIL; | 435 return FAIL; |
436 } | 436 } |
437 | 437 |
438 *arg = name_end; | 438 *arg = name_end; |
447 { | 447 { |
448 ufunc_T *fp = cl->class_obj_methods[m_idx]; | 448 ufunc_T *fp = cl->class_obj_methods[m_idx]; |
449 // Private methods are not accessible outside the class | 449 // Private methods are not accessible outside the class |
450 if (*name == '_' && !inside_class(cctx, cl)) | 450 if (*name == '_' && !inside_class(cctx, cl)) |
451 { | 451 { |
452 semsg(_(e_cannot_access_private_method_str), fp->uf_name); | 452 semsg(_(e_cannot_access_protected_method_str), fp->uf_name); |
453 return FAIL; | 453 return FAIL; |
454 } | 454 } |
455 *arg = name_end; | 455 *arg = name_end; |
456 // Remove the object type from the stack | 456 // Remove the object type from the stack |
457 --cctx->ctx_type_stack.ga_len; | 457 --cctx->ctx_type_stack.ga_len; |
470 // Note: type->tt_type = VAR_CLASS | 470 // Note: type->tt_type = VAR_CLASS |
471 // A private class variable can be accessed only in the class where | 471 // A private class variable can be accessed only in the class where |
472 // it is defined. | 472 // it is defined. |
473 if (*name == '_' && cctx->ctx_ufunc->uf_class != cl) | 473 if (*name == '_' && cctx->ctx_ufunc->uf_class != cl) |
474 { | 474 { |
475 emsg_var_cl_define(e_cannot_access_private_variable_str, | 475 emsg_var_cl_define(e_cannot_access_protected_variable_str, |
476 m->ocm_name, 0, cl); | 476 m->ocm_name, 0, cl); |
477 return FAIL; | 477 return FAIL; |
478 } | 478 } |
479 | 479 |
480 *arg = name_end; | 480 *arg = name_end; |
489 { | 489 { |
490 ufunc_T *fp = cl->class_class_functions[m_idx]; | 490 ufunc_T *fp = cl->class_class_functions[m_idx]; |
491 // Private methods are not accessible outside the class | 491 // Private methods are not accessible outside the class |
492 if (*name == '_' && !inside_class(cctx, cl)) | 492 if (*name == '_' && !inside_class(cctx, cl)) |
493 { | 493 { |
494 semsg(_(e_cannot_access_private_method_str), fp->uf_name); | 494 semsg(_(e_cannot_access_protected_method_str), fp->uf_name); |
495 return FAIL; | 495 return FAIL; |
496 } | 496 } |
497 *arg = name_end; | 497 *arg = name_end; |
498 // Remove the class type from the stack | 498 // Remove the class type from the stack |
499 --cctx->ctx_type_stack.ga_len; | 499 --cctx->ctx_type_stack.ga_len; |