comparison src/vim9expr.c @ 33173:9efd99a717c1 v9.0.1867

patch 9.0.1867: Vim9: access to interface statics possible Commit: https://github.com/vim/vim/commit/18143d3111b2122c7a94ca51085a60b3073cb139 Author: Ernie Rael <errael@raelity.com> Date: Mon Sep 4 22:30:41 2023 +0200 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>
author Christian Brabandt <cb@256bit.org>
date Mon, 04 Sep 2023 22:45:04 +0200
parents 2b5cc29b0a0e
children 52b121d4feb5
comparison
equal deleted inserted replaced
33172:6564d48fe98a 33173:9efd99a717c1
405 return FAIL; 405 return FAIL;
406 } 406 }
407 407
408 *arg = name_end; 408 *arg = name_end;
409 if (cl->class_flags & (CLASS_INTERFACE | CLASS_EXTENDED)) 409 if (cl->class_flags & (CLASS_INTERFACE | CLASS_EXTENDED))
410 return generate_GET_ITF_MEMBER(cctx, cl, i, m->ocm_type); 410 return generate_GET_ITF_MEMBER(cctx, cl, i, m->ocm_type,
411 return generate_GET_OBJ_MEMBER(cctx, i, m->ocm_type); 411 FALSE);
412 return generate_GET_OBJ_MEMBER(cctx, i, m->ocm_type, FALSE);
413 }
414 }
415
416 for (int i = 0; i < cl->class_class_member_count; ++i)
417 {
418 ocmember_T *m = &cl->class_class_members[i];
419 if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL)
420 {
421 if (*name == '_' && !inside_class(cctx, cl))
422 {
423 semsg(_(e_cannot_access_private_member_str), m->ocm_name);
424 return FAIL;
425 }
426 *arg = name_end;
427 if (cl->class_flags & (CLASS_INTERFACE | CLASS_EXTENDED))
428 return generate_GET_ITF_MEMBER(cctx, cl, i, m->ocm_type,
429 TRUE);
430 return generate_GET_OBJ_MEMBER(cctx, i, m->ocm_type, TRUE);
412 } 431 }
413 } 432 }
414 433
415 // Could be a function reference: "obj.Func". 434 // Could be a function reference: "obj.Func".
416 for (int i = 0; i < cl->class_obj_method_count; ++i) 435 for (int i = 0; i < cl->class_obj_method_count; ++i)
437 for (idx = 0; idx < cl->class_class_member_count; ++idx) 456 for (idx = 0; idx < cl->class_class_member_count; ++idx)
438 { 457 {
439 ocmember_T *m = &cl->class_class_members[idx]; 458 ocmember_T *m = &cl->class_class_members[idx];
440 if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL) 459 if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL)
441 { 460 {
461 // Note: type->tt_type = VAR_CLASS
462 if ((cl->class_flags & CLASS_INTERFACE) != 0)
463 {
464 semsg(_(e_interface_static_direct_access_str),
465 cl->class_name, m->ocm_name);
466 return FAIL;
467 }
442 if (*name == '_' && !inside_class(cctx, cl)) 468 if (*name == '_' && !inside_class(cctx, cl))
443 { 469 {
444 semsg(_(e_cannot_access_private_member_str), m->ocm_name); 470 semsg(_(e_cannot_access_private_member_str), m->ocm_name);
445 return FAIL; 471 return FAIL;
446 } 472 }