@@ -148,6 +148,7 @@ static char e_syntax_at[] = N_("E1002: Syntax error at %s");
148148static char e_used_as_arg [] = N_ ("E1006: %s is used as an argument" );
149149static char e_cannot_use_void [] = N_ ("E1031: Cannot use void value" );
150150static char e_namespace [] = N_ ("E1075: Namespace not supported: %s" );
151+ static char e_unknown_var [] = N_ ("E1089: unknown variable: %s" );
151152
152153static void delete_def_function_contents (dfunc_T * dfunc );
153154static void arg_type_mismatch (type_T * expected , type_T * actual , int argidx );
@@ -5335,7 +5336,6 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
53355336 else
53365337 {
53375338 int idx ;
5338- imported_T * import = NULL ;
53395339
53405340 for (idx = 0 ; reserved [idx ] != NULL ; ++ idx )
53415341 if (STRCMP (reserved [idx ], name ) == 0 )
@@ -5374,49 +5374,67 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
53745374 goto theend ;
53755375 }
53765376 }
5377- else if ((varlen > 1 && STRNCMP (var_start , "s:" , 2 ) == 0 )
5378- || lookup_script (var_start , varlen ) == OK
5379- || (import = find_imported (var_start , varlen , cctx ))
5380- != NULL )
5377+ else
53815378 {
5382- char_u * rawname = name + (name [1 ] == ':' ? 2 : 0 );
5383-
5384- if (is_decl )
5379+ int script_namespace = varlen > 1
5380+ && STRNCMP (var_start , "s:" , 2 ) == 0 ;
5381+ int script_var = (script_namespace
5382+ ? lookup_script (var_start + 2 , varlen - 2 )
5383+ : lookup_script (var_start , varlen )) == OK ;
5384+ imported_T * import =
5385+ find_imported (var_start , varlen , cctx );
5386+
5387+ if (script_namespace || script_var || import != NULL )
53855388 {
5386- if ((varlen > 1 && STRNCMP (var_start , "s:" , 2 ) == 0 ))
5387- semsg (_ ("E1101: Cannot declare a script variable in a function: %s" ),
5389+ char_u * rawname = name + (name [1 ] == ':' ? 2 : 0 );
5390+
5391+ if (is_decl )
5392+ {
5393+ if (script_namespace )
5394+ semsg (_ ("E1101: Cannot declare a script variable in a function: %s" ),
53885395 name );
5389- else
5390- semsg (_ ("E1054: Variable already declared in the script: %s" ),
5396+ else
5397+ semsg (_ ("E1054: Variable already declared in the script: %s" ),
53915398 name );
5392- goto theend ;
5393- }
5394- dest = dest_script ;
5399+ goto theend ;
5400+ }
5401+ else if (cctx -> ctx_ufunc -> uf_script_ctx_version
5402+ == SCRIPT_VERSION_VIM9
5403+ && script_namespace
5404+ && !script_var && import == NULL )
5405+ {
5406+ semsg (_ (e_unknown_var ), name );
5407+ goto theend ;
5408+ }
5409+
5410+ dest = dest_script ;
53955411
5396- // existing script-local variables should have a type
5397- scriptvar_sid = current_sctx .sc_sid ;
5398- if (import != NULL )
5399- scriptvar_sid = import -> imp_sid ;
5400- scriptvar_idx = get_script_item_idx (scriptvar_sid ,
5412+ // existing script-local variables should have a type
5413+ scriptvar_sid = current_sctx .sc_sid ;
5414+ if (import != NULL )
5415+ scriptvar_sid = import -> imp_sid ;
5416+ scriptvar_idx = get_script_item_idx (scriptvar_sid ,
54015417 rawname , TRUE);
5402- if (scriptvar_idx >= 0 )
5403- {
5404- scriptitem_T * si = SCRIPT_ITEM (scriptvar_sid );
5405- svar_T * sv = ((svar_T * )si -> sn_var_vals .ga_data )
5418+ if (scriptvar_idx >= 0 )
5419+ {
5420+ scriptitem_T * si = SCRIPT_ITEM (scriptvar_sid );
5421+ svar_T * sv =
5422+ ((svar_T * )si -> sn_var_vals .ga_data )
54065423 + scriptvar_idx ;
5407- type = sv -> sv_type ;
5424+ type = sv -> sv_type ;
5425+ }
54085426 }
5409- }
5410- else if (name [1 ] == ':' && name [2 ] != NUL )
5411- {
5412- semsg (_ ("E1082: Cannot use a namespaced variable: %s" ),
5427+ else if (name [1 ] == ':' && name [2 ] != NUL )
5428+ {
5429+ semsg (_ ("E1082: Cannot use a namespaced variable: %s" ),
54135430 name );
5414- goto theend ;
5415- }
5416- else if (!is_decl )
5417- {
5418- semsg (_ ("E1089: unknown variable: %s" ), name );
5419- goto theend ;
5431+ goto theend ;
5432+ }
5433+ else if (!is_decl )
5434+ {
5435+ semsg (_ (e_unknown_var ), name );
5436+ goto theend ;
5437+ }
54205438 }
54215439 }
54225440
0 commit comments