@@ -5070,6 +5070,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
50705070 char_u * ret = NULL ;
50715071 int var_count = 0 ;
50725072 int var_idx ;
5073+ int scriptvar_sid = 0 ;
5074+ int scriptvar_idx = -1 ;
50735075 int semicolon = 0 ;
50745076 garray_T * instr = & cctx -> ctx_instr ;
50755077 garray_T * stack = & cctx -> ctx_type_stack ;
@@ -5333,7 +5335,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
53335335 }
53345336 else
53355337 {
5336- int idx ;
5338+ int idx ;
5339+ imported_T * import = NULL ;
53375340
53385341 for (idx = 0 ; reserved [idx ] != NULL ; ++ idx )
53395342 if (STRCMP (reserved [idx ], name ) == 0 )
@@ -5374,9 +5377,11 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
53745377 }
53755378 else if ((varlen > 1 && STRNCMP (var_start , "s:" , 2 ) == 0 )
53765379 || lookup_script (var_start , varlen ) == OK
5377- || find_imported (var_start , varlen , cctx ) != NULL )
5380+ || (import = find_imported (var_start , varlen , cctx ))
5381+ != NULL )
53785382 {
5379- dest = dest_script ;
5383+ char_u * rawname = name + (name [1 ] == ':' ? 2 : 0 );
5384+
53805385 if (is_decl )
53815386 {
53825387 if ((varlen > 1 && STRNCMP (var_start , "s:" , 2 ) == 0 ))
@@ -5387,6 +5392,21 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
53875392 name );
53885393 goto theend ;
53895394 }
5395+ dest = dest_script ;
5396+
5397+ // existing script-local variables should have a type
5398+ scriptvar_sid = current_sctx .sc_sid ;
5399+ if (import != NULL )
5400+ scriptvar_sid = import -> imp_sid ;
5401+ scriptvar_idx = get_script_item_idx (scriptvar_sid ,
5402+ rawname , TRUE);
5403+ if (scriptvar_idx >= 0 )
5404+ {
5405+ scriptitem_T * si = SCRIPT_ITEM (scriptvar_sid );
5406+ svar_T * sv = ((svar_T * )si -> sn_var_vals .ga_data )
5407+ + scriptvar_idx ;
5408+ type = sv -> sv_type ;
5409+ }
53905410 }
53915411 else if (name [1 ] == ':' && name [2 ] != NUL )
53925412 {
@@ -5766,21 +5786,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
57665786 break ;
57675787 case dest_script :
57685788 {
5769- char_u * rawname = name + (name [1 ] == ':' ? 2 : 0 );
5770- imported_T * import = NULL ;
5771- int sid = current_sctx .sc_sid ;
5772- int idx ;
5773-
5774- if (name [1 ] != ':' )
5775- {
5776- import = find_imported (name , 0 , cctx );
5777- if (import != NULL )
5778- sid = import -> imp_sid ;
5779- }
5780-
5781- idx = get_script_item_idx (sid , rawname , TRUE);
5782- // TODO: specific type
5783- if (idx < 0 )
5789+ if (scriptvar_idx < 0 )
57845790 {
57855791 char_u * name_s = name ;
57865792
@@ -5796,14 +5802,14 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
57965802 vim_snprintf ((char * )name_s , len ,
57975803 "s:%s" , name );
57985804 }
5799- generate_OLDSCRIPT (cctx , ISN_STORES , name_s , sid ,
5800- & t_any );
5805+ generate_OLDSCRIPT (cctx , ISN_STORES , name_s ,
5806+ scriptvar_sid , type );
58015807 if (name_s != name )
58025808 vim_free (name_s );
58035809 }
58045810 else
58055811 generate_VIM9SCRIPT (cctx , ISN_STORESCRIPT ,
5806- sid , idx , & t_any );
5812+ scriptvar_sid , scriptvar_idx , type );
58075813 }
58085814 break ;
58095815 case dest_local :
0 commit comments