Skip to content

Commit 9de59f5

Browse files
committed
:let throws E46 when assigning to readonly variable
1 parent 18ddad5 commit 9de59f5

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/cmd_line/commands/let.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,37 @@ export class LetCommand extends ExCommand {
198198
};
199199

200200
if (variable.type === 'variable') {
201+
if (
202+
variable.namespace === 'v' &&
203+
variable.name in
204+
[
205+
'count',
206+
'false',
207+
'key',
208+
'null',
209+
'operator',
210+
'prevcount',
211+
'progname',
212+
'progpath',
213+
'servername',
214+
'shell_error',
215+
'swapname',
216+
't_bool',
217+
't_dict',
218+
't_float',
219+
't_func',
220+
't_list',
221+
't_number',
222+
't_string',
223+
't_blob',
224+
'true',
225+
'val',
226+
'version',
227+
'vim_did_enter',
228+
]
229+
) {
230+
throw VimError.fromCode(ErrorCode.CannotChangeReadOnlyVariable);
231+
}
201232
context.setVariable(variable, newValue(variable, value), this.args.lock);
202233
} else if (variable.type === 'register') {
203234
// TODO

src/error.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export enum ErrorCode {
1414
NoPreviousCommand = 34,
1515
NoPreviousRegularExpression = 35,
1616
NoWriteSinceLastChange = 37,
17+
CannotChangeReadOnlyVariable = 46,
1718
MultipleMatches = 93,
1819
NoMatchingBuffer = 94,
1920
NoSuchVariable = 108,
@@ -108,6 +109,7 @@ export const ErrorMessage: IErrorMessage = {
108109
34: 'No previous command',
109110
35: 'No previous regular expression',
110111
37: 'No write since last change (add ! to override)',
112+
46: 'Cannot change read-only variable',
111113
93: 'More than one match',
112114
94: 'No matching buffer',
113115
108: 'No such variable',

0 commit comments

Comments
 (0)