Skip to content

Commit 843039f

Browse files
committed
throw more specific errors
1 parent 29ea240 commit 843039f

13 files changed

+23
-0
lines changed

autoload/vimlparser.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,14 @@ function! s:VimLParser.parse_constlvalue()
19161916
endif
19171917
if node.type == s:NODE_IDENTIFIER || node.type == s:NODE_CURLYNAME
19181918
return node
1919+
elseif node.type == s:NODE_SUBSCRIPT || node.type == s:NODE_SLICE || node.type == s:NODE_DOT
1920+
throw s:Err('E996: Cannot lock a list or dict', node.pos)
1921+
elseif node.type == s:NODE_OPTION
1922+
throw s:Err('E996: Cannot lock an option', node.pos)
1923+
elseif node.type == s:NODE_ENV
1924+
throw s:Err('E996: Cannot lock an environment variable', node.pos)
1925+
elseif node.type == s:NODE_REG
1926+
throw s:Err('E996: Cannot lock a register', node.pos)
19191927
endif
19201928
throw s:Err('Invalid Expression', node.pos)
19211929
endfunction

test/test_err_const1.ok

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vimlparser: E996: Cannot lock a list or dict: line 2 col 8

test/test_err_const1.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let a = [0]
2+
const a[0] = 1

test/test_err_const2.ok

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vimlparser: E996: Cannot lock a list or dict: line 2 col 8

test/test_err_const2.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let a = {}
2+
const a["b"] = 1

test/test_err_const3.ok

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vimlparser: E996: Cannot lock a list or dict: line 2 col 8

test/test_err_const3.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let a = {}
2+
const a.b = 1

test/test_err_const4.ok

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vimlparser: E996: Cannot lock an environment variable: line 1 col 7

test/test_err_const4.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const $a = 1

test/test_err_const5.ok

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vimlparser: E996: Cannot lock a register: line 1 col 7

0 commit comments

Comments
 (0)