From f1750ca0c2ef91c6e4857655ca8fdf8dd8f5abb8 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Tue, 2 Apr 2024 20:41:04 +0200 Subject: patch 9.1.0257: Vim9: :call may not find imported class members Problem: Vim9: :call may not find imported class members (mityu) Solution: Set the typval of an imported lval variable correctly (Yegappan Lakshmanan) fixes: #14334 closes: #14386 Signed-off-by: Yegappan Lakshmanan Signed-off-by: Christian Brabandt --- src/testdir/test_vim9_class.vim | 39 +++++++++++++++++++++++++++++++++++++++ src/testdir/test_vim9_import.vim | 14 ++++++++++++++ 2 files changed, 53 insertions(+) (limited to 'src/testdir') diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim index cf900f7630..93481d55b8 100644 --- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -3121,6 +3121,28 @@ def Test_class_import() v9.CheckScriptSuccess(lines) enddef +" Test for importing a class into a legacy script and calling the class method +def Test_class_method_from_legacy_script() + var lines =<< trim END + vim9script + export class A + static var name: string = 'a' + static def SetName(n: string) + name = n + enddef + endclass + END + writefile(lines, 'Xvim9export.vim', 'D') + + lines =<< trim END + import './Xvim9export.vim' as vim9 + + call s:vim9.A.SetName('b') + call assert_equal('b', s:vim9.A.name) + END + v9.CheckScriptSuccess(lines) +enddef + " Test for implementing an imported interface def Test_implement_imported_interface() var lines =<< trim END @@ -3220,6 +3242,23 @@ def Test_abstract_class() endclass END v9.CheckSourceFailure(lines, 'E1359: Cannot define a "new" method in an abstract class', 4) + + # extending an abstract class with class methods and variables + lines =<< trim END + vim9script + abstract class A + static var s: string = 'vim' + static def Fn(): list + return [10] + enddef + endclass + class B extends A + endclass + var b = B.new() + assert_equal('vim', A.s) + assert_equal([10], A.Fn()) + END + v9.CheckScriptSuccess(lines) enddef def Test_closure_in_class() diff --git a/src/testdir/test_vim9_import.vim b/src/testdir/test_vim9_import.vim index fa1aeb10e8..8d68f1e47e 100644 --- a/src/testdir/test_vim9_import.vim +++ b/src/testdir/test_vim9_import.vim @@ -2054,6 +2054,13 @@ def Test_import_vim9_from_legacy() export def GetText(): string return 'text' enddef + export var exported_nr: number = 22 + def AddNum(n: number) + exported_nr += n + enddef + export var exportedDict: dict = {Fn: AddNum} + export const CONST = 10 + export final finalVar = 'abc' END writefile(vim9_lines, 'Xvim9_export.vim', 'D') @@ -2072,6 +2079,13 @@ def Test_import_vim9_from_legacy() " imported symbol is script-local call assert_equal('exported', s:vim9.exported) call assert_equal('text', s:vim9.GetText()) + call s:vim9.exportedDict.Fn(5) + call assert_equal(27, s:vim9.exported_nr) + call call(s:vim9.exportedDict.Fn, [3]) + call assert_equal(30, s:vim9.exported_nr) + call assert_fails('let s:vim9.CONST = 20', 'E46: Cannot change read-only variable "CONST"') + call assert_fails('let s:vim9.finalVar = ""', 'E46: Cannot change read-only variable "finalVar"') + call assert_fails('let s:vim9.non_existing_var = 20', 'E1048: Item not found in script: non_existing_var') END writefile(legacy_lines, 'Xlegacy_script.vim', 'D') -- cgit v1.2.3