summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErnie Rael <errael@raelity.com>2023-03-03 15:05:30 +0000
committerBram Moolenaar <Bram@vim.org>2023-03-03 15:05:30 +0000
commitf77a7f704ffd0ca1050e82f609c8b8bd61863277 (patch)
tree6b7a7b0aa8b48066a9d2661deb86e29da02ac554
parentc727b19e9f1df36e44321d933334c7b4961daa54 (diff)
patch 9.0.1375: crash when getting member of obj of unknown classv9.0.1375
Problem: Crash when getting member of obj of unknown class. Solution: Check for NULL class and give an error message. (Ernie Rael, closes #12096)
-rw-r--r--src/errors.h2
-rw-r--r--src/testdir/test_vim9_class.vim19
-rw-r--r--src/version.c2
-rw-r--r--src/vim9expr.c7
4 files changed, 30 insertions, 0 deletions
diff --git a/src/errors.h b/src/errors.h
index f1c36ad7bb..445a9b8d6e 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -3452,4 +3452,6 @@ EXTERN char e_cannot_use_color_none_did_you_mean_none[]
#ifdef FEAT_EVAL
EXTERN char e_cannot_use_non_null_object[]
INIT(= N_("E1362: Cannot use a non-null object"));
+EXTERN char e_incomplete_type[]
+ INIT(= N_("E1363: Incomplete type"));
#endif
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index c228f2642b..bc8a8e1d54 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -272,6 +272,25 @@ def Test_object_not_set()
echo Colorscheme.new(bg).GetBackground()
END
v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected object<Background> but got object<Unknown>')
+
+ # TODO: this should not give an error but be handled at runtime
+ lines =<< trim END
+ vim9script
+
+ class Class
+ this.id: string
+ def Method1()
+ echo 'Method1' .. this.id
+ enddef
+ endclass
+
+ var obj = null_object
+ def Func()
+ obj.Method1()
+ enddef
+ Func()
+ END
+ v9.CheckScriptFailure(lines, 'E1363:')
enddef
def Test_class_member_initializer()
diff --git a/src/version.c b/src/version.c
index 1caf5b24d0..8f26bdf47a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1375,
+/**/
1374,
/**/
1373,
diff --git a/src/vim9expr.c b/src/vim9expr.c
index b8458aa417..d600cb0ae1 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -293,6 +293,13 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type)
}
}
+ if (cl == NULL)
+ {
+ // TODO: this should not give an error but be handled at runtime
+ emsg(_(e_incomplete_type));
+ return FAIL;
+ }
+
++*arg;
char_u *name = *arg;
char_u *name_end = find_name_end(name, NULL, NULL, FNE_CHECK_START);