[vim/vim] Fix import and class extends E1001 issue (Try again) (PR #16602)

37 views
Skip to first unread message

h_east

unread,
Feb 9, 2025, 10:41:38 AM2/9/25
to vim/vim, Subscribed

Fix: #16379
Related: #16440


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/16602

Commit Summary

  • 084abd8 Fix import and extends E1001 issue

File Changes

(2 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602@github.com>

h_east

unread,
Feb 9, 2025, 10:54:53 AM2/9/25
to vim/vim, Push

@h-east pushed 1 commit.

  • d3c5d90 Fix import and extends E1001 issue


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/before/084abd8e6ac7bf16c1e1e3ec09682ad23e9c6c19/after/d3c5d908d9c135f314cae6eaebb24db30c7064a9@github.com>

h_east

unread,
Feb 9, 2025, 8:40:17 PM2/9/25
to vim/vim, Subscribed

@yegappan Could you review this PR?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2646740104@github.com>

Yegappan Lakshmanan

unread,
Feb 9, 2025, 9:32:02 PM2/9/25
to vim/vim, Subscribed

@yegappan Could you review this PR?

Yes. Reviewing the changes.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2646786922@github.com>

Yegappan Lakshmanan

unread,
Feb 9, 2025, 11:41:34 PM2/9/25
to vim/vim, Subscribed

This PR doesn't fix the issue when multi-level imports are used:

test.vim:

vim9script
import './cccc.vim'
class MyView extends cccc.View
    def new(v: string)
        this._content.value = v
    enddef
endclass
var myView = MyView.new('This should be ok')
echo myView

cccc.vim:

vim9script
import "./bbbb.vim"
export class View
  var _content = bbbb.Data.new()
endclass

bbbb.vim:

vim9script
import "./aaaa.vim"
export class Data
    var _d = aaaa.Property.new('xxx')
endclass

aaaa.vim:

vim9script
export class Property
  public var value: string = 'aaa'
endclass


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2646904327@github.com>

Yegappan Lakshmanan

unread,
Feb 10, 2025, 12:06:18 AM2/10/25
to vim/vim, Subscribed

This PR doesn't fix the issue when multi-level imports are used:

Ignore this comment. I made a mistake in the script. After making the below changes to the script, the PR does work.

test.vim:

vim9script
import './cccc.vim'
class MyView extends cccc.View
    def new(v: string)
        this._content.value = v

This should be "this._content.d.value = v".

enddef

endclass
var myView = MyView.new('This should be ok')
echo myView


cccc.vim:

vim9script
import "./bbbb.vim"
export class View
var _content = bbbb.Data.new()
endclass


bbbb.vim:

vim9script
import "./aaaa.vim"
export class Data
var _d = aaaa.Property.new('xxx')

This should be "var d = ...".

endclass


aaaa.vim:

vim9script
export class Property
public var value: string = 'aaa'
endclass


When you source test.vim, the message 'E1326: Variable "value" not found in object "Data"' is displayed.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2646929341@github.com>

Yegappan Lakshmanan

unread,
Feb 10, 2025, 12:07:12 AM2/10/25
to vim/vim, Subscribed

@yegappan commented on this pull request.


In src/vim9compile.c:

> +		    && cl_extends->class_class_function_count_child > 0)
+		check_extends = TRUE;
+
+	    if (check_extends)
+		++emsg_skip;
+	    ret = compile_expr0(&expr, cctx);
+	    if (check_extends)
+		--emsg_skip;
+	    if (ret == FAIL && check_extends)
+	    {
+		sctx_T current_sctx_save = current_sctx;
+
+		expr = m->ocm_init;
+		current_sctx =
+			cl_extends->class_class_functions[0]->uf_script_ctx;
+		//current_sctx.sc_seq = current_sctx_save.sc_seq;

The commented out line should be removed?


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/review/2604698451@github.com>

h_east

unread,
Feb 10, 2025, 12:15:14 AM2/10/25
to vim/vim, Subscribed

@h-east commented on this pull request.


In src/vim9compile.c:

> +		    && cl_extends->class_class_function_count_child > 0)
+		check_extends = TRUE;
+
+	    if (check_extends)
+		++emsg_skip;
+	    ret = compile_expr0(&expr, cctx);
+	    if (check_extends)
+		--emsg_skip;
+	    if (ret == FAIL && check_extends)
+	    {
+		sctx_T current_sctx_save = current_sctx;
+
+		expr = m->ocm_init;
+		current_sctx =
+			cl_extends->class_class_functions[0]->uf_script_ctx;
+		//current_sctx.sc_seq = current_sctx_save.sc_seq;

Yes, I'll remove it after I get home.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/review/2604705594@github.com>

h_east

unread,
Feb 10, 2025, 5:52:57 AM2/10/25
to vim/vim, Push

@h-east pushed 1 commit.

  • 0d0fb2e Fix import and extends E1001 issue

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/before/d3c5d908d9c135f314cae6eaebb24db30c7064a9/after/0d0fb2e55aaac59f2c7bd7eeb495a565ed924885@github.com>

h_east

unread,
Feb 10, 2025, 5:54:05 AM2/10/25
to vim/vim, Subscribed

@h-east commented on this pull request.


In src/vim9compile.c:

> +		    && cl_extends->class_class_function_count_child > 0)
+		check_extends = TRUE;
+
+	    if (check_extends)
+		++emsg_skip;
+	    ret = compile_expr0(&expr, cctx);
+	    if (check_extends)
+		--emsg_skip;
+	    if (ret == FAIL && check_extends)
+	    {
+		sctx_T current_sctx_save = current_sctx;
+
+		expr = m->ocm_init;
+		current_sctx =
+			cl_extends->class_class_functions[0]->uf_script_ctx;
+		//current_sctx.sc_seq = current_sctx_save.sc_seq;

Done.
Thanks for reviewing 👍


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/review/2605388068@github.com>

Christian Brabandt

unread,
Feb 10, 2025, 3:41:08 PM2/10/25
to vim/vim, Subscribed

are we good here?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2649185365@github.com>

h_east

unread,
Feb 10, 2025, 7:42:38 PM2/10/25
to vim/vim, Subscribed

are we good here?

Perhaps we could address it deeper inside (e.g. compile_expr9() or compile_load() or etc...) rather than before compile_expr0().
That would probably make more sense.
I'll try it.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2649570468@github.com>

h_east

unread,
Feb 11, 2025, 6:46:47 AM2/11/25
to vim/vim, Subscribed

I'll try it.

Done.
Actually, this issue might need to be addressed within find_imported(), but since there are many call points,
So, I created find_imported_from_extends() and handled only the necessary parts for this issue.
If similar issues arise in the future, it may be necessary to consider addressing them in find_imported().


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2650569393@github.com>

h_east

unread,
Feb 11, 2025, 6:46:49 AM2/11/25
to vim/vim, Push

@h-east pushed 1 commit.

  • 41df957 Fix import and extends E1001 issue

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/before/0d0fb2e55aaac59f2c7bd7eeb495a565ed924885/after/41df957db9fde8a33a85e4f9ed464647136b8cb1@github.com>

h_east

unread,
Feb 11, 2025, 6:48:45 AM2/11/25
to vim/vim, Subscribed

@yegappan Could you please re-review it?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2650573536@github.com>

h_east

unread,
Feb 11, 2025, 7:43:54 AM2/11/25
to vim/vim, Push

@h-east pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/before/41df957db9fde8a33a85e4f9ed464647136b8cb1/after/6e52aed14b4b3b731abc405cc85a24f2d69c7fa0@github.com>

h_east

unread,
Feb 11, 2025, 9:21:29 AM2/11/25
to vim/vim, Subscribed

ASAN error has occurred.

Since 9.1.1097 !?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2650965410@github.com>

Christian Brabandt

unread,
Feb 11, 2025, 4:10:59 PM2/11/25
to vim/vim, Subscribed

might be the newly added test and how we run system('vim --log /Xfoobar'). I am trying to find a better way to test it.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2652075056@github.com>

h_east

unread,
Feb 12, 2025, 6:30:51 AM2/12/25
to vim/vim, Push

@h-east pushed 2 commits.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/before/6e52aed14b4b3b731abc405cc85a24f2d69c7fa0/after/8f039ecf50753cdd7b1bd031d563fca086c49e15@github.com>

Christian Brabandt

unread,
Feb 12, 2025, 2:42:13 PM2/12/25
to vim/vim, Subscribed

@yegappan do you approve?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2654683446@github.com>

Yegappan Lakshmanan

unread,
Feb 13, 2025, 1:43:53 AM2/13/25
to vim/vim, Subscribed

@yegappan approved this pull request.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/review/2614001223@github.com>

Yegappan Lakshmanan

unread,
Feb 13, 2025, 1:44:11 AM2/13/25
to vim/vim, Subscribed

@yegappan do you approve?

@chrisbra Yes.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2655672861@github.com>

h_east

unread,
Feb 13, 2025, 6:16:34 AM2/13/25
to vim/vim, Push

@h-east pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/before/8f039ecf50753cdd7b1bd031d563fca086c49e15/after/f71c6375bba8aaf09e36831ff0952972fb3186aa@github.com>

Yegappan Lakshmanan

unread,
Feb 13, 2025, 11:24:38 AM2/13/25
to vim/vim, Subscribed

@yegappan commented on this pull request.


In src/vim9compile.c:

> + * Find "name" in imported items of extended base class of the class to which
+ * the context :def function belongs.
+ */
+    imported_T *
+find_imported_from_extends(cctx_T *cctx, char_u *name, size_t len, int load)
+{
+    imported_T	*ret = NULL;
+    class_T	*cl_extends;
+
+    if (cctx == NULL || cctx->ctx_ufunc == NULL
+					|| cctx->ctx_ufunc->uf_class == NULL)
+	return NULL;
+
+    cl_extends = cctx->ctx_ufunc->uf_class->class_extends;
+
+    if (cl_extends != NULL && cl_extends->class_class_function_count_child > 0)

Can you use early return here also?

if (cl_extends == NULL || cl_extends->class_class_function_count_child <= 0)
    return NULL;


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/review/2615588043@github.com>

Christian Brabandt

unread,
Feb 13, 2025, 3:09:48 PM2/13/25
to vim/vim, Subscribed

@chrisbra commented on this pull request.


In src/vim9compile.c:

> + * Find "name" in imported items of extended base class of the class to which
+ * the context :def function belongs.
+ */
+    imported_T *
+find_imported_from_extends(cctx_T *cctx, char_u *name, size_t len, int load)
+{
+    imported_T	*ret = NULL;
+    class_T	*cl_extends;
+
+    if (cctx == NULL || cctx->ctx_ufunc == NULL
+					|| cctx->ctx_ufunc->uf_class == NULL)
+	return NULL;
+
+    cl_extends = cctx->ctx_ufunc->uf_class->class_extends;
+
+    if (cl_extends != NULL && cl_extends->class_class_function_count_child > 0)

I'll include that change, thanks


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/review/2616111443@github.com>

Christian Brabandt

unread,
Feb 13, 2025, 3:11:34 PM2/13/25
to vim/vim, Subscribed

Closed #16602 via bf7c88d.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/issue_event/16302154720@github.com>

h_east

unread,
Feb 13, 2025, 6:52:15 PM2/13/25
to vim/vim, Subscribed

Thank you for the review and the follow-up 👍


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2657946082@github.com>

h-easth-east left a comment (vim/vim#16602)

Thank you for the review and the follow-up 👍


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16602/c2657946082@github.com>

Reply all
Reply to author
Forward
0 new messages