@@ -301,28 +301,6 @@ script_var_exists(char_u *name, size_t len, cctx_T *cctx, cstack_T *cstack)
301301 return FAIL ;
302302}
303303
304- /*
305- * If "name" is a class member in cctx->ctx_ufunc->uf_class return the index in
306- * class.class_class_members[].
307- * Otherwise return -1;
308- */
309- static int
310- class_member_index (char_u * name , size_t len , cctx_T * cctx )
311- {
312- if (cctx == NULL || cctx -> ctx_ufunc == NULL
313- || cctx -> ctx_ufunc -> uf_class == NULL )
314- return -1 ;
315- class_T * cl = cctx -> ctx_ufunc -> uf_class ;
316- for (int i = 0 ; i < cl -> class_class_member_count ; ++ i )
317- {
318- ocmember_T * m = & cl -> class_class_members [i ];
319- if (STRNCMP (name , m -> ocm_name , len ) == 0
320- && m -> ocm_name [len ] == NUL )
321- return i ;
322- }
323- return -1 ;
324- }
325-
326304/*
327305 * Return TRUE if "name" is a local variable, argument, script variable or
328306 * imported.
@@ -338,7 +316,7 @@ variable_exists(char_u *name, size_t len, cctx_T *cctx)
338316 && (cctx -> ctx_ufunc -> uf_flags & FC_OBJECT )
339317 && STRNCMP (name , "this" , 4 ) == 0 )))
340318 || script_var_exists (name , len , cctx , NULL ) == OK
341- || class_member_index (name , len , cctx ) >= 0
319+ || class_member_index (name , len , NULL , cctx ) >= 0
342320 || find_imported (name , len , FALSE) != NULL ;
343321}
344322
@@ -376,9 +354,6 @@ check_defined(
376354 if (len == 1 && * p == '_' )
377355 return OK ;
378356
379- if (class_member_index (p , len , cctx ) >= 0 )
380- return OK ;
381-
382357 if (script_var_exists (p , len , cctx , cstack ) == OK )
383358 {
384359 if (is_arg )
@@ -388,6 +363,15 @@ check_defined(
388363 return FAIL ;
389364 }
390365
366+ if (class_member_index (p , len , NULL , cctx ) >= 0 )
367+ {
368+ if (is_arg )
369+ semsg (_ (e_argument_already_declared_in_class_str ), p );
370+ else
371+ semsg (_ (e_variable_already_declared_in_class_str ), p );
372+ return FAIL ;
373+ }
374+
391375 p [len ] = NUL ;
392376 if ((cctx != NULL
393377 && (lookup_local (p , len , NULL , cctx ) == OK
@@ -1592,8 +1576,14 @@ compile_lhs(
15921576 }
15931577 }
15941578 else if ((lhs -> lhs_classmember_idx = class_member_index (
1595- var_start , lhs -> lhs_varlen , cctx )) >= 0 )
1579+ var_start , lhs -> lhs_varlen , NULL , cctx )) >= 0 )
15961580 {
1581+ if (is_decl )
1582+ {
1583+ semsg (_ (e_variable_already_declared_in_class_str ),
1584+ lhs -> lhs_name );
1585+ return FAIL ;
1586+ }
15971587 lhs -> lhs_dest = dest_class_member ;
15981588 lhs -> lhs_class = cctx -> ctx_ufunc -> uf_class ;
15991589 }
@@ -2264,7 +2254,7 @@ compile_assignment(
22642254 CLEAR_FIELD (lhs );
22652255 long start_lnum = SOURCING_LNUM ;
22662256
2267- int has_arg_is_set_prefix = STRNCMP (arg , "ifargisset " , 11 ) == 0 ;
2257+ int has_arg_is_set_prefix = STRNCMP (arg , "ifargisset " , 11 ) == 0 ;
22682258 if (has_arg_is_set_prefix )
22692259 {
22702260 arg += 11 ;
0 commit comments