[vim/vim] E1041 is thrown when a variable is exported from a script contained in the autoload/ folder and the script is sourced more than once (Issue #19205)

3 views
Skip to first unread message

ubaldot

unread,
Jan 17, 2026, 11:31:07 PMJan 17
to vim/vim, Subscribed
ubaldot created an issue (vim/vim#19205)

Steps to reproduce

Create ~/vimfiles/autoload/x.vim with the following content:

vim9script

export enum Fruit
  Banana,
  Apple
endenum

If you source it twice, then you get E1041.

If you move away the script from autoload folders, then you can source it as many way as you want.

Expected behaviour

It should be possible to source the script as many times as user want without throwing any error.

Version of Vim

9.1-1942

Environment

Win 11

Logs and stack traces


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

h_east

unread,
Feb 3, 2026, 8:34:58 AM (19 hours ago) Feb 3
to vim/vim, Subscribed
h-east left a comment (vim/vim#19205)

This seems working as expected.
Files under autoload/ update the loaded information for the file path name (x in this case) the first time they are loaded.
The first time :so is used, the loaded information for the file path name (x) is internally updated to indicate that it has been loaded, but the second time :so is used, the file has already been loaded, resulting in an E1041 error.

Normally, Vim9 scripts use import autoload for the autoload mechanism.
This allows control that loads only the first time to work correctly.

vim9script

import autoload 'x.vim'

var f = x#Fruit.Banana
echo $"f: {f.name}"


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/19205/3841359203@github.com>

h_east

unread,
Feb 3, 2026, 9:55:41 AM (17 hours ago) Feb 3
to vim/vim, Subscribed
h-east left a comment (vim/vim#19205)

@yegappan What is your take on this?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/19205/3841820954@github.com>

ubaldot

unread,
Feb 3, 2026, 1:01:06 PM (14 hours ago) Feb 3
to vim/vim, Subscribed
ubaldot left a comment (vim/vim#19205)

So what is the point of having noclear and why moving scripts in another folder won't suffer the same problem. The current behavior is cumbersome in vim9 context.

I could understand such a behavior in legacy-vim (and for every script), but definitely not in Vin9.
In vim9 you have noclear if you really want such a behavior.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/19205/3842679884@github.com>

h_east

unread,
12:20 AM (3 hours ago) 12:20 AM
to vim/vim, Subscribed
h-east left a comment (vim/vim#19205)

Normal def functions can be redefined, but since enum/class are part of the type system, I believe redefining them is prohibited due to compatibility issues with existing instances.

I think you should either use import autoload, or define export enum and export class outside of autoload/.

If you are developing a plugin and have made changes to autoload/x.vim, restart Vim.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/19205/3845396662@github.com>

Reply all
Reply to author
Forward
0 new messages