Skip to content

Commit e3fed48

Browse files
yegappanchrisbra
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 106899e commit e3fed48

3 files changed

Lines changed: 95 additions & 63 deletions

File tree

src/testdir/test_vim9_import.vim

Lines changed: 91 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3494,75 +3494,105 @@ def Test_vim9_import_and_class_extends_2()
34943494
&rtp = save_rtp
34953495
enddef
34963496

3497-
" Test for using an autoloaded class from another autoloaded script
3498-
def Test_class_from_auloaded_script()
3497+
" Test for using an imported class as a type
3498+
def Test_use_imported_class_as_type()
34993499
mkdir('Xdir', 'R')
3500-
var save_rtp = &rtp
3501-
&rtp = getcwd()
3502-
exe 'set rtp^=' .. getcwd() .. '/Xdir'
3503-
3504-
mkdir('Xdir/autoload/SomeClass/bar', 'p')
3505-
3500+
mkdir('Xdir/autoload', 'D')
3501+
mkdir('Xdir/import', 'D')
35063502
var lines =<< trim END
35073503
vim9script
3508-
3509-
export class Baz
3510-
static var v1: string = "v1"
3511-
var v2: string = "v2"
3512-
def GetName(): string
3513-
return "baz"
3504+
export class B
3505+
var foo: string
3506+
def new()
3507+
this.foo = 'bar'
35143508
enddef
35153509
endclass
35163510
END
3517-
writefile(lines, 'Xdir/autoload/SomeClass/bar/baz.vim', 'D')
3511+
writefile(lines, 'Xdir/autoload/b.vim')
35183512

35193513
lines =<< trim END
35203514
vim9script
3521-
3522-
import autoload './bar/baz.vim'
3523-
3524-
export def MyTestFoo(): string
3525-
assert_fails('var x = baz.Baz.NonExisting()', 'E1325: Method "NonExisting" not found in class "Baz"')
3526-
assert_fails('var x = baz.Baz.foobar', 'E1337: Class variable "foobar" not found in class "Baz"')
3527-
3528-
const instance = baz.Baz.new()
3529-
return $'{instance.GetName()} {baz.Baz.v1} {instance.v2}'
3530-
enddef
3531-
END
3532-
writefile(lines, 'Xdir/autoload/SomeClass/foo.vim', 'D')
3533-
3534-
lines =<< trim END
3535-
vim9script
3536-
3537-
import autoload 'SomeClass/foo.vim'
3538-
import autoload 'SomeClass/bar/baz.vim'
3539-
3540-
def NotInAutoload()
3541-
# Use non-existing class method and variable
3542-
assert_fails('var x = baz.Baz.NonExisting()', 'E1325: Method "NonExisting" not found in class "Baz"')
3543-
3544-
var caught_exception = false
3545-
try
3546-
var x = baz.Baz.foobar
3547-
catch /E1337: Class variable "foobar" not found in class "Baz"/
3548-
caught_exception = true
3549-
endtry
3550-
assert_true(caught_exception)
3551-
3552-
const instance = baz.Baz.new()
3553-
assert_equal("baz v1 v2", $'{instance.GetName()} {baz.Baz.v1} {instance.v2}')
3554-
enddef
3555-
3556-
def InAutoload()
3557-
assert_equal("baz v1 v2", foo.MyTestFoo())
3558-
enddef
3559-
3560-
NotInAutoload()
3561-
InAutoload()
3562-
END
3563-
v9.CheckScriptSuccess(lines)
3564-
3565-
&rtp = save_rtp
3566-
enddef
3515+
import autoload '../autoload/b.vim'
3516+
export class A
3517+
final AO: b.B = b.B.new()
3518+
endclass
3519+
var a = A.new()
3520+
assert_equal('bar', a.AO.foo)
3521+
END
3522+
writefile(lines, 'Xdir/import/a.vim')
3523+
source Xdir/import/a.vim
3524+
enddef
3525+
3526+
" FIXME: The following test currently fails.
3527+
" " Test for using an autoloaded class from another autoloaded script
3528+
" def Test_class_from_auloaded_script()
3529+
" mkdir('Xdir', 'R')
3530+
" var save_rtp = &rtp
3531+
" &rtp = getcwd()
3532+
" exe 'set rtp^=' .. getcwd() .. '/Xdir'
3533+
"
3534+
" mkdir('Xdir/autoload/SomeClass/bar', 'p')
3535+
"
3536+
" var lines =<< trim END
3537+
" vim9script
3538+
"
3539+
" export class Baz
3540+
" static var v1: string = "v1"
3541+
" var v2: string = "v2"
3542+
" def GetName(): string
3543+
" return "baz"
3544+
" enddef
3545+
" endclass
3546+
" END
3547+
" writefile(lines, 'Xdir/autoload/SomeClass/bar/baz.vim', 'D')
3548+
"
3549+
" lines =<< trim END
3550+
" vim9script
3551+
"
3552+
" import autoload './bar/baz.vim'
3553+
"
3554+
" export def MyTestFoo(): string
3555+
" assert_fails('var x = baz.Baz.NonExisting()', 'E1325: Method "NonExisting" not found in class "Baz"')
3556+
" assert_fails('var x = baz.Baz.foobar', 'E1337: Class variable "foobar" not found in class "Baz"')
3557+
"
3558+
" const instance = baz.Baz.new()
3559+
" return $'{instance.GetName()} {baz.Baz.v1} {instance.v2}'
3560+
" enddef
3561+
" END
3562+
" writefile(lines, 'Xdir/autoload/SomeClass/foo.vim', 'D')
3563+
"
3564+
" lines =<< trim END
3565+
" vim9script
3566+
"
3567+
" import autoload 'SomeClass/foo.vim'
3568+
" import autoload 'SomeClass/bar/baz.vim'
3569+
"
3570+
" def NotInAutoload()
3571+
" # Use non-existing class method and variable
3572+
" assert_fails('var x = baz.Baz.NonExisting()', 'E1325: Method "NonExisting" not found in class "Baz"')
3573+
"
3574+
" var caught_exception = false
3575+
" try
3576+
" var x = baz.Baz.foobar
3577+
" catch /E1337: Class variable "foobar" not found in class "Baz"/
3578+
" caught_exception = true
3579+
" endtry
3580+
" assert_true(caught_exception)
3581+
"
3582+
" const instance = baz.Baz.new()
3583+
" assert_equal("baz v1 v2", $'{instance.GetName()} {baz.Baz.v1} {instance.v2}')
3584+
" enddef
3585+
"
3586+
" def InAutoload()
3587+
" assert_equal("baz v1 v2", foo.MyTestFoo())
3588+
" enddef
3589+
"
3590+
" NotInAutoload()
3591+
" InAutoload()
3592+
" END
3593+
" v9.CheckScriptSuccess(lines)
3594+
"
3595+
" &rtp = save_rtp
3596+
" enddef
35673597

35683598
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1128,
707709
/**/
708710
1127,
709711
/**/

src/vim9class.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ ex_class(exarg_T *eap)
20532053
tv.v_type = VAR_CLASS;
20542054
tv.vval.v_class = cl;
20552055
SOURCING_LNUM = start_lnum;
2056-
int rc = set_var_const(cl->class_name, 0, NULL, &tv, FALSE, 0, 0);
2056+
int rc = set_var_const(cl->class_name, current_sctx.sc_sid, NULL, &tv, FALSE, 0, 0);
20572057
if (rc == FAIL)
20582058
goto cleanup;
20592059

@@ -2873,7 +2873,7 @@ ex_type(exarg_T *eap)
28732873
tv.vval.v_class = type->tt_class;
28742874
++tv.vval.v_class->class_refcount;
28752875
}
2876-
set_var_const(name_start, 0, NULL, &tv, FALSE,
2876+
set_var_const(name_start, current_sctx.sc_sid, NULL, &tv, FALSE,
28772877
ASSIGN_CONST | ASSIGN_FINAL, 0);
28782878

28792879
done:

0 commit comments

Comments
 (0)