patch 9.1.1128: patch 9.1.1119 caused a regression with imports Commit: https://github.com/vim/vim/commit/e3fed4828c0f909bef25e184c6c19bb0cab8adef Author: Yegappan Lakshmanan <yegap...@yahoo.com> Date: Thu Feb 20 22:20:54 2025 +0100
patch 9.1.1128: patch 9.1.1119 caused a regression with imports Problem: patch 9.1.1119 caused a regression with imports (girishji) Solution: revert the script ID change for the class script variable for now (Yegappan Lakshmanan) fixes: #16664 closes: #16670 Signed-off-by: Yegappan Lakshmanan <yegap...@yahoo.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/testdir/test_vim9_import.vim b/src/testdir/test_vim9_import.vim index 8d81697b2..6937fb3c2 100644 --- a/src/testdir/test_vim9_import.vim +++ b/src/testdir/test_vim9_import.vim @@ -3494,75 +3494,105 @@ def Test_vim9_import_and_class_extends_2() &rtp = save_rtp enddef -" Test for using an autoloaded class from another autoloaded script -def Test_class_from_auloaded_script() +" Test for using an imported class as a type +def Test_use_imported_class_as_type() mkdir('Xdir', 'R') - var save_rtp = &rtp - &rtp = getcwd() - exe 'set rtp^=' .. getcwd() .. '/Xdir' - - mkdir('Xdir/autoload/SomeClass/bar', 'p') - + mkdir('Xdir/autoload', 'D') + mkdir('Xdir/import', 'D') var lines =<< trim END vim9script - - export class Baz - static var v1: string = "v1" - var v2: string = "v2" - def GetName(): string - return "baz" + export class B + var foo: string + def new() + this.foo = 'bar' enddef endclass END - writefile(lines, 'Xdir/autoload/SomeClass/bar/baz.vim', 'D') + writefile(lines, 'Xdir/autoload/b.vim') lines =<< trim END vim9script - - import autoload './bar/baz.vim' - - export def MyTestFoo(): string - assert_fails('var x = baz.Baz.NonExisting()', 'E1325: Method "NonExisting" not found in class "Baz"') - assert_fails('var x = baz.Baz.foobar', 'E1337: Class variable "foobar" not found in class "Baz"') - - const instance = baz.Baz.new() - return $'{instance.GetName()} {baz.Baz.v1} {instance.v2}' - enddef - END - writefile(lines, 'Xdir/autoload/SomeClass/foo.vim', 'D') - - lines =<< trim END - vim9script - - import autoload 'SomeClass/foo.vim' - import autoload 'SomeClass/bar/baz.vim' - - def NotInAutoload() - # Use non-existing class method and variable - assert_fails('var x = baz.Baz.NonExisting()', 'E1325: Method "NonExisting" not found in class "Baz"') - - var caught_exception = false - try - var x = baz.Baz.foobar - catch /E1337: Class variable "foobar" not found in class "Baz"/ - caught_exception = true - endtry - assert_true(caught_exception) - - const instance = baz.Baz.new() - assert_equal("baz v1 v2", $'{instance.GetName()} {baz.Baz.v1} {instance.v2}') - enddef - - def InAutoload() - assert_equal("baz v1 v2", foo.MyTestFoo()) - enddef - - NotInAutoload() - InAutoload() - END - v9.CheckScriptSuccess(lines) - - &rtp = save_rtp -enddef + import autoload '../autoload/b.vim' + export class A + final AO: b.B = b.B.new() + endclass + var a = A.new() + assert_equal('bar', a.AO.foo) + END + writefile(lines, 'Xdir/import/a.vim') + source Xdir/import/a.vim +enddef + +" FIXME: The following test currently fails. +" " Test for using an autoloaded class from another autoloaded script +" def Test_class_from_auloaded_script() +" mkdir('Xdir', 'R') +" var save_rtp = &rtp +" &rtp = getcwd() +" exe 'set rtp^=' .. getcwd() .. '/Xdir' +" +" mkdir('Xdir/autoload/SomeClass/bar', 'p') +" +" var lines =<< trim END +" vim9script +" +" export class Baz +" static var v1: string = "v1" +" var v2: string = "v2" +" def GetName(): string +" return "baz" +" enddef +" endclass +" END +" writefile(lines, 'Xdir/autoload/SomeClass/bar/baz.vim', 'D') +" +" lines =<< trim END +" vim9script +" +" import autoload './bar/baz.vim' +" +" export def MyTestFoo(): string +" assert_fails('var x = baz.Baz.NonExisting()', 'E1325: Method "NonExisting" not found in class "Baz"') +" assert_fails('var x = baz.Baz.foobar', 'E1337: Class variable "foobar" not found in class "Baz"') +" +" const instance = baz.Baz.new() +" return $'{instance.GetName()} {baz.Baz.v1} {instance.v2}' +" enddef +" END +" writefile(lines, 'Xdir/autoload/SomeClass/foo.vim', 'D') +" +" lines =<< trim END +" vim9script +" +" import autoload 'SomeClass/foo.vim' +" import autoload 'SomeClass/bar/baz.vim' +" +" def NotInAutoload() +" # Use non-existing class method and variable +" assert_fails('var x = baz.Baz.NonExisting()', 'E1325: Method "NonExisting" not found in class "Baz"') +" +" var caught_exception = false +" try +" var x = baz.Baz.foobar +" catch /E1337: Class variable "foobar" not found in class "Baz"/ +" caught_exception = true +" endtry +" assert_true(caught_exception) +" +" const instance = baz.Baz.new() +" assert_equal("baz v1 v2", $'{instance.GetName()} {baz.Baz.v1} {instance.v2}') +" enddef +" +" def InAutoload() +" assert_equal("baz v1 v2", foo.MyTestFoo()) +" enddef +" +" NotInAutoload() +" InAutoload() +" END +" v9.CheckScriptSuccess(lines) +" +" &rtp = save_rtp +" enddef " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker diff --git a/src/version.c b/src/version.c index fad08acae..fc3164666 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1128, /**/ 1127, /**/ diff --git a/src/vim9class.c b/src/vim9class.c index f0413425f..dc13c4b2e 100644 --- a/src/vim9class.c +++ b/src/vim9class.c @@ -2053,7 +2053,7 @@ early_ret: tv.v_type = VAR_CLASS; tv.vval.v_class = cl; SOURCING_LNUM = start_lnum; - int rc = set_var_const(cl->class_name, 0, NULL, &tv, FALSE, 0, 0); + int rc = set_var_const(cl->class_name, current_sctx.sc_sid, NULL, &tv, FALSE, 0, 0); if (rc == FAIL) goto cleanup; @@ -2873,7 +2873,7 @@ ex_type(exarg_T *eap) tv.vval.v_class = type->tt_class; ++tv.vval.v_class->class_refcount; } - set_var_const(name_start, 0, NULL, &tv, FALSE, + set_var_const(name_start, current_sctx.sc_sid, NULL, &tv, FALSE, ASSIGN_CONST | ASSIGN_FINAL, 0); done: -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1tlE7R-003Bkn-TL%40256bit.org.