Patch 9.0.1355

2 views
Skip to first unread message

Bram Moolenaar

unread,
Feb 25, 2023, 3:00:01 PM2/25/23
to vim...@googlegroups.com

Patch 9.0.1355
Problem: No error when declaring a class twice. (Ernie Rael)
Solution: Pass different flags when declaring the class. (closes #12057)
Files: src/vim9class.c, src/testdir/test_vim9_class.vim


*** ../vim-9.0.1354/src/vim9class.c 2023-02-21 12:38:46.827436713 +0000
--- src/vim9class.c 2023-02-25 19:50:56.601262949 +0000
***************
*** 230,236 ****
void
ex_class(exarg_T *eap)
{
! int is_class = eap->cmdidx == CMD_class; // FALSE for :interface

char_u *arg = eap->arg;
int is_abstract = eap->cmdidx == CMD_abstract;
--- 230,237 ----
void
ex_class(exarg_T *eap)
{
! int is_class = eap->cmdidx == CMD_class; // FALSE for :interface
! long start_lnum = SOURCING_LNUM;

char_u *arg = eap->arg;
int is_abstract = eap->cmdidx == CMD_abstract;
***************
*** 1097,1104 ****
tv.v_type = VAR_CLASS;
tv.vval.v_class = cl;
is_export = class_export;
set_var_const(cl->class_name, current_sctx.sc_sid,
! NULL, &tv, FALSE, ASSIGN_DECL, 0);
return;
}

--- 1098,1106 ----
tv.v_type = VAR_CLASS;
tv.vval.v_class = cl;
is_export = class_export;
+ SOURCING_LNUM = start_lnum;
set_var_const(cl->class_name, current_sctx.sc_sid,
! NULL, &tv, FALSE, 0, 0);
return;
}

*** ../vim-9.0.1354/src/testdir/test_vim9_class.vim 2023-02-21 19:55:02.795958051 +0000
--- src/testdir/test_vim9_class.vim 2023-02-25 19:57:03.596589607 +0000
***************
*** 164,169 ****
--- 164,191 ----
v9.CheckScriptSuccess(lines)
enddef

+ def Test_class_defined_twice()
+ # class defined twice should fail
+ var lines =<< trim END
+ vim9script
+ class There
+ endclass
+ class There
+ endclass
+ END
+ v9.CheckScriptFailure(lines, 'E1041: Redefining script item: "There"')
+
+ # one class, reload same script twice is OK
+ lines =<< trim END
+ vim9script
+ class There
+ endclass
+ END
+ writefile(lines, 'XclassTwice.vim', 'D')
+ source XclassTwice.vim
+ source XclassTwice.vim
+ enddef
+
def Test_class_interface_wrong_end()
var lines =<< trim END
vim9script
***************
*** 1012,1025 ****
this.member: string
endinterface

! class SomeImpl implements Some, Another
this.member = 'abc'
static count: number
def Method(nr: number)
echo nr
enddef
endclass
-
END
v9.CheckScriptSuccess(lines)

--- 1034,1046 ----
this.member: string
endinterface

! class AnotherImpl implements Some, Another
this.member = 'abc'
static count: number
def Method(nr: number)
echo nr
enddef
endclass
END
v9.CheckScriptSuccess(lines)

*** ../vim-9.0.1354/src/version.c 2023-02-25 14:24:39.573937238 +0000
--- src/version.c 2023-02-25 19:54:54.844778300 +0000
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1355,
/**/

--
hundred-and-one symptoms of being an internet addict:
178. You look for an icon to double-click to open your bedroom window.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages