@@ -538,11 +538,12 @@ compile_load_scriptvar(
538538 cctx_T * cctx ,
539539 char_u * name , // variable NUL terminated
540540 char_u * start , // start of variable
541- char_u * * end ) // end of variable, may be NULL
541+ char_u * * end , // end of variable, may be NULL
542+ imported_T * import ) // found imported item, can be NULL
542543{
543544 scriptitem_T * si ;
544545 int idx ;
545- imported_T * import ;
546+ imported_T * imp ;
546547
547548 if (!SCRIPT_ID_VALID (current_sctx .sc_sid ))
548549 return FAIL ;
@@ -557,8 +558,14 @@ compile_load_scriptvar(
557558 return OK ;
558559 }
559560
560- import = end == NULL ? NULL : find_imported (name , 0 , FALSE);
561- if (import != NULL )
561+ if (end == NULL )
562+ imp = NULL ;
563+ else if (import == NULL )
564+ imp = find_imported (name , 0 , FALSE);
565+ else
566+ imp = import ;
567+
568+ if (imp != NULL )
562569 {
563570 char_u * p = skipwhite (* end );
564571 char_u * exp_name ;
@@ -568,8 +575,8 @@ compile_load_scriptvar(
568575 int done = FALSE;
569576 int res = OK ;
570577
571- check_script_symlink (import -> imp_sid );
572- import_check_sourced_sid (& import -> imp_sid );
578+ check_script_symlink (imp -> imp_sid );
579+ import_check_sourced_sid (& imp -> imp_sid );
573580
574581 // Need to lookup the member.
575582 if (* p != '.' )
@@ -591,11 +598,11 @@ compile_load_scriptvar(
591598 cc = * p ;
592599 * p = NUL ;
593600
594- si = SCRIPT_ITEM (import -> imp_sid );
601+ si = SCRIPT_ITEM (imp -> imp_sid );
595602 if (si -> sn_import_autoload && si -> sn_state == SN_STATE_NOT_LOADED )
596603 // "import autoload './dir/script.vim'" or
597604 // "import autoload './autoload/script.vim'" - load script first
598- res = generate_SOURCE (cctx , import -> imp_sid );
605+ res = generate_SOURCE (cctx , imp -> imp_sid );
599606
600607 if (res == OK )
601608 {
@@ -624,17 +631,17 @@ compile_load_scriptvar(
624631 {
625632 char_u sid_name [MAX_FUNC_NAME_LEN ];
626633
627- func_name_with_sid (exp_name , import -> imp_sid , sid_name );
634+ func_name_with_sid (exp_name , imp -> imp_sid , sid_name );
628635 res = generate_PUSHFUNC (cctx , sid_name , & t_func_any , TRUE);
629636 }
630637 else
631638 res = generate_OLDSCRIPT (cctx , ISN_LOADEXPORT , exp_name ,
632- import -> imp_sid , & t_any );
639+ imp -> imp_sid , & t_any );
633640 done = TRUE;
634641 }
635642 else
636643 {
637- idx = find_exported (import -> imp_sid , exp_name , & ufunc , & type ,
644+ idx = find_exported (imp -> imp_sid , exp_name , & ufunc , & type ,
638645 cctx , NULL , TRUE);
639646 }
640647 }
@@ -656,7 +663,7 @@ compile_load_scriptvar(
656663 }
657664
658665 generate_VIM9SCRIPT (cctx , ISN_LOADSCRIPT ,
659- import -> imp_sid ,
666+ imp -> imp_sid ,
660667 idx ,
661668 type );
662669 return OK ;
@@ -751,7 +758,7 @@ compile_load(
751758 res = generate_funcref (cctx , name , FALSE);
752759 else
753760 res = compile_load_scriptvar (cctx , name ,
754- NULL , & end );
761+ NULL , & end , NULL );
755762 break ;
756763 case 'g' : if (vim_strchr (name , AUTOLOAD_CHAR ) == NULL )
757764 {
@@ -869,11 +876,15 @@ compile_load(
869876 }
870877 else
871878 {
879+ imported_T * imp = NULL ;
880+
872881 // "var" can be script-local even without using "s:" if it
873882 // already exists in a Vim9 script or when it's imported.
874883 if (script_var_exists (* arg , len , cctx , NULL ) == OK
875- || find_imported (name , 0 , FALSE) != NULL )
876- res = compile_load_scriptvar (cctx , name , * arg , & end );
884+ || (imp = find_imported (name , 0 , FALSE)) != NULL
885+ || (imp = find_imported_from_extends (cctx , name , 0 , FALSE))
886+ != NULL )
887+ res = compile_load_scriptvar (cctx , name , * arg , & end , imp );
877888
878889 // When evaluating an expression and the name starts with an
879890 // uppercase letter it can be a user defined function.
0 commit comments