diff --git a/autoload/vimlparser.vim b/autoload/vimlparser.vim index 24e98a2..29e5b50 100644 --- a/autoload/vimlparser.vim +++ b/autoload/vimlparser.vim @@ -569,19 +569,36 @@ function! s:VimLParser.declare(node) abort endfunction function! s:VimLParser.push_context(node) abort - if a:node.type ==# s:NODE_DEF || a:node.type ==# s:NODE_FUNCTION + " Functions have their own scope. In Vim9 script a block also has its own + " scope, also at the script level. + if a:node.type ==# s:NODE_DEF || a:node.type ==# s:NODE_FUNCTION || a:node.type ==# s:NODE_BLOCK + \ || (self.isvim9() && (a:node.type ==# s:NODE_IF || a:node.type ==# s:NODE_WHILE || a:node.type ==# s:NODE_FOR || a:node.type ==# s:NODE_TRY)) call self.push_scope() + call insert(self.scope_nodes, a:node) endif call insert(self.context, a:node) endfunction function! s:VimLParser.pop_context() abort - if self.context[0].type ==# s:NODE_DEF || self.context[0].type ==# s:NODE_FUNCTION + if !empty(self.scope_nodes) && self.scope_nodes[0] is# self.context[0] call self.pop_scope() + call remove(self.scope_nodes, 0) endif call remove(self.context, 0) endfunction +" Names declared in one branch of :if or :try are not visible in the next +" branch: go back to the names known before the :if or :try. +function! s:VimLParser.reset_branch_scope() abort + if !empty(self.scope_nodes) && self.scope_nodes[0] is# self.context[0] + let declared = {} + for name in keys(self.outer_declared[0]) + let declared[name] = 1 + endfor + let self.declared = declared + endif +endfunction + " Names declared in a function or lambda are only visible inside it: continue " with a copy of the declared names and restore them with pop_scope(). function! s:VimLParser.push_scope() abort @@ -692,6 +709,8 @@ function! s:VimLParser.parse_toplevel(reader) abort " command. let self.declared = {} let self.outer_declared = [] + " Context nodes that started a scope with push_scope(). + let self.scope_nodes = [] " Names in :def functions that were not declared when they were parsed. let self.undeclared_in_def = {} call self.push_context(toplevel) @@ -2970,6 +2989,7 @@ function! s:VimLParser.parse_cmd_elseif() abort if self.context[0].type !=# s:NODE_IF call self.pop_context() endif + call self.reset_branch_scope() let node = s:Node(s:NODE_ELSEIF) let node.pos = self.ea.cmdpos let node.body = [] @@ -2986,6 +3006,7 @@ function! s:VimLParser.parse_cmd_else() abort if self.context[0].type !=# s:NODE_IF call self.pop_context() endif + call self.reset_branch_scope() let node = s:Node(s:NODE_ELSE) let node.pos = self.ea.cmdpos let node.body = [] @@ -3046,13 +3067,6 @@ function! s:VimLParser.parse_cmd_for() abort let node.left = lhs.left let node.list = lhs.list let node.rest = lhs.rest - call self.declare(node.left) - if node.list isnot# s:NIL - for x in node.list - call self.declare(x) - endfor - endif - call self.declare(node.rest) call self.reader.skip_white() let epos = self.reader.getpos() if self.reader.read_alpha() !=# 'in' @@ -3061,6 +3075,14 @@ function! s:VimLParser.parse_cmd_for() abort let node.right = self.parse_expr() call self.add_node(node) call self.push_context(node) + " The loop variables are only visible inside the loop in Vim9 script. + call self.declare(node.left) + if node.list isnot# s:NIL + for x in node.list + call self.declare(x) + endfor + endif + call self.declare(node.rest) endfunction " Vim9 :for loop variables with optional types: "name: type" or @@ -3144,6 +3166,7 @@ function! s:VimLParser.parse_cmd_catch() abort if self.context[0].type !=# s:NODE_TRY call self.pop_context() endif + call self.reset_branch_scope() let node = s:Node(s:NODE_CATCH) let node.pos = self.ea.cmdpos let node.body = [] @@ -3164,6 +3187,7 @@ function! s:VimLParser.parse_cmd_finally() abort if self.context[0].type !=# s:NODE_TRY call self.pop_context() endif + call self.reset_branch_scope() let node = s:Node(s:NODE_FINALLY) let node.pos = self.ea.cmdpos let node.body = [] diff --git a/js/vimlparser.js b/js/vimlparser.js index c229208..0a12878 100644 --- a/js/vimlparser.js +++ b/js/vimlparser.js @@ -753,27 +753,45 @@ VimLParser.prototype.declare = function(node) { } VimLParser.prototype.push_context = function(node) { - if (node.type == NODE_DEF || node.type == NODE_FUNCTION) { + // Functions have their own scope. In Vim9 script a block also has its own + // scope, also at the script level. + if (node.type == NODE_DEF || node.type == NODE_FUNCTION || node.type == NODE_BLOCK || this.isvim9() && (node.type == NODE_IF || node.type == NODE_WHILE || node.type == NODE_FOR || node.type == NODE_TRY)) { this.push_scope(); + viml_insert(this.scope_nodes, node); } viml_insert(this.context, node); } VimLParser.prototype.pop_context = function() { - if (this.context[0].type == NODE_DEF || this.context[0].type == NODE_FUNCTION) { + if (!viml_empty(this.scope_nodes) && this.scope_nodes[0] === this.context[0]) { this.pop_scope(); + viml_remove(this.scope_nodes, 0); } viml_remove(this.context, 0); } +// Names declared in one branch of :if or :try are not visible in the next +// branch: go back to the names known before the :if or :try. +VimLParser.prototype.reset_branch_scope = function() { + if (!viml_empty(this.scope_nodes) && this.scope_nodes[0] === this.context[0]) { + var declared = {}; + var __c6 = viml_keys(this.outer_declared[0]); + for (var __i6 = 0; __i6 < __c6.length; ++__i6) { + var name = __c6[__i6]; + declared[name] = 1; + } + this.declared = declared; + } +} + // Names declared in a function or lambda are only visible inside it: continue // with a copy of the declared names and restore them with pop_scope(). VimLParser.prototype.push_scope = function() { viml_insert(this.outer_declared, this.declared); var declared = {}; - var __c6 = viml_keys(this.declared); - for (var __i6 = 0; __i6 < __c6.length; ++__i6) { - var name = __c6[__i6]; + var __c7 = viml_keys(this.declared); + for (var __i7 = 0; __i7 < __c7.length; ++__i7) { + var name = __c7[__i7]; declared[name] = 1; } this.declared = declared; @@ -799,9 +817,9 @@ VimLParser.prototype.is_declared = function(name) { VimLParser.prototype.find_context = function(type) { var i = 0; - var __c7 = this.context; - for (var __i7 = 0; __i7 < __c7.length; ++__i7) { - var node = __c7[__i7]; + var __c8 = this.context; + for (var __i8 = 0; __i8 < __c8.length; ++__i8) { + var node = __c8[__i8]; if (node.type == type) { return i; } @@ -859,9 +877,9 @@ VimLParser.prototype.parse = function(reader) { var vim9script = this.vim9script; this.script_declared = {}; var toplevel = this.parse_toplevel(reader); - var __c8 = viml_keys(this.undeclared_in_def); - for (var __i8 = 0; __i8 < __c8.length; ++__i8) { - var name = __c8[__i8]; + var __c9 = viml_keys(this.undeclared_in_def); + for (var __i9 = 0; __i9 < __c9.length; ++__i9) { + var name = __c9[__i9]; if (viml_has_key(this.declared, name)) { this.script_declared = this.declared; this.vim9script = vim9script; @@ -882,6 +900,8 @@ VimLParser.prototype.parse_toplevel = function(reader) { // command. this.declared = {}; this.outer_declared = []; + // Context nodes that started a scope with push_scope(). + this.scope_nodes = []; // Names in :def functions that were not declared when they were parsed. this.undeclared_in_def = {}; this.push_context(toplevel); @@ -1514,9 +1534,9 @@ VimLParser.prototype.parse_command = function() { } // In legacy script :final is an abbreviation of :finally. if (this.ea.cmd.name == "final" && !this.isvim9()) { - var __c9 = this.builtin_commands; - for (var __i9 = 0; __i9 < __c9.length; ++__i9) { - var x = __c9[__i9]; + var __c10 = this.builtin_commands; + for (var __i10 = 0; __i10 < __c10.length; ++__i10) { + var x = __c10[__i10]; if (x.name == "finally") { this.ea.cmd = x; break; @@ -1831,9 +1851,9 @@ VimLParser.prototype.find_command = function() { return this.find_command_cache[name]; } var cmd = NIL; - var __c10 = this.builtin_commands; - for (var __i10 = 0; __i10 < __c10.length; ++__i10) { - var x = __c10[__i10]; + var __c11 = this.builtin_commands; + for (var __i11 = 0; __i11 < __c11.length; ++__i11) { + var x = __c11[__i11]; if (viml_stridx(x.name, name) == 0 && viml_len(name) >= x.minlen) { delete cmd; var cmd = x; @@ -1841,18 +1861,18 @@ VimLParser.prototype.find_command = function() { } } if (this.neovim) { - var __c11 = this.neovim_additional_commands; - for (var __i11 = 0; __i11 < __c11.length; ++__i11) { - var x = __c11[__i11]; + var __c12 = this.neovim_additional_commands; + for (var __i12 = 0; __i12 < __c12.length; ++__i12) { + var x = __c12[__i12]; if (viml_stridx(x.name, name) == 0 && viml_len(name) >= x.minlen) { delete cmd; var cmd = x; break; } } - var __c12 = this.neovim_removed_commands; - for (var __i12 = 0; __i12 < __c12.length; ++__i12) { - var x = __c12[__i12]; + var __c13 = this.neovim_removed_commands; + for (var __i13 = 0; __i13 < __c13.length; ++__i13) { + var x = __c13[__i13]; if (viml_stridx(x.name, name) == 0 && viml_len(name) >= x.minlen) { delete cmd; var cmd = NIL; @@ -2919,9 +2939,9 @@ VimLParser.prototype.parse_vim9_decl = function(type) { throw Err(viml_printf("E475: Invalid argument: %s", c), this.reader.getpos()); } } - var __c13 = node.list; - for (var __i13 = 0; __i13 < __c13.length; ++__i13) { - var x = __c13[__i13]; + var __c14 = node.list; + for (var __i14 = 0; __i14 < __c14.length; ++__i14) { + var x = __c14[__i14]; this.declare(x); } this.declare(node.rest); @@ -3341,6 +3361,7 @@ VimLParser.prototype.parse_cmd_elseif = function() { if (this.context[0].type != NODE_IF) { this.pop_context(); } + this.reset_branch_scope(); var node = Node(NODE_ELSEIF); node.pos = this.ea.cmdpos; node.body = []; @@ -3357,6 +3378,7 @@ VimLParser.prototype.parse_cmd_else = function() { if (this.context[0].type != NODE_IF) { this.pop_context(); } + this.reset_branch_scope(); var node = Node(NODE_ELSE); node.pos = this.ea.cmdpos; node.body = []; @@ -3418,15 +3440,6 @@ VimLParser.prototype.parse_cmd_for = function() { node.left = lhs.left; node.list = lhs.list; node.rest = lhs.rest; - this.declare(node.left); - if (node.list !== NIL) { - var __c14 = node.list; - for (var __i14 = 0; __i14 < __c14.length; ++__i14) { - var x = __c14[__i14]; - this.declare(x); - } - } - this.declare(node.rest); this.reader.skip_white(); var epos = this.reader.getpos(); if (this.reader.read_alpha() != "in") { @@ -3435,6 +3448,16 @@ VimLParser.prototype.parse_cmd_for = function() { node.right = this.parse_expr(); this.add_node(node); this.push_context(node); + // The loop variables are only visible inside the loop in Vim9 script. + this.declare(node.left); + if (node.list !== NIL) { + var __c15 = node.list; + for (var __i15 = 0; __i15 < __c15.length; ++__i15) { + var x = __c15[__i15]; + this.declare(x); + } + } + this.declare(node.rest); } // Vim9 :for loop variables with optional types: "name: type" or @@ -3520,6 +3543,7 @@ VimLParser.prototype.parse_cmd_catch = function() { if (this.context[0].type != NODE_TRY) { this.pop_context(); } + this.reset_branch_scope(); var node = Node(NODE_CATCH); node.pos = this.ea.cmdpos; node.body = []; @@ -3542,6 +3566,7 @@ VimLParser.prototype.parse_cmd_finally = function() { if (this.context[0].type != NODE_TRY) { this.pop_context(); } + this.reset_branch_scope(); var node = Node(NODE_FINALLY); node.pos = this.ea.cmdpos; node.body = []; @@ -5899,9 +5924,9 @@ StringReader.prototype.__init__ = function(lines) { } while (lnum < viml_len(lines)) { var col = 0; - var __c15 = viml_split(lines[lnum], "\\zs"); - for (var __i15 = 0; __i15 < __c15.length; ++__i15) { - var c = __c15[__i15]; + var __c16 = viml_split(lines[lnum], "\\zs"); + for (var __i16 = 0; __i16 < __c16.length; ++__i16) { + var c = __c16[__i16]; viml_add(this.buf, c); viml_add(this.pos, [lnum + 1, col + 1, offset]); col += viml_len(c); @@ -5921,9 +5946,9 @@ StringReader.prototype.__init__ = function(lines) { } var skip = TRUE; var col = 0; - var __c16 = viml_split(lines[lnum + 1], "\\zs"); - for (var __i16 = 0; __i16 < __c16.length; ++__i16) { - var c = __c16[__i16]; + var __c17 = viml_split(lines[lnum + 1], "\\zs"); + for (var __i17 = 0; __i17 < __c17.length; ++__i17) { + var c = __c17[__i17]; if (skip) { if (c == "\\") { var skip = FALSE; @@ -6025,9 +6050,9 @@ StringReader.prototype.readline = function() { StringReader.prototype.getstr = function(begin, end) { var r = ""; - var __c17 = viml_range(begin.i, end.i - 1); - for (var __i17 = 0; __i17 < __c17.length; ++__i17) { - var i = __c17[__i17]; + var __c18 = viml_range(begin.i, end.i - 1); + for (var __i18 = 0; __i18 < __c18.length; ++__i18) { + var i = __c18[__i18]; if (i >= viml_len(this.buf)) { break; } @@ -6606,9 +6631,9 @@ Compiler.prototype.compile = function(node) { } Compiler.prototype.compile_body = function(body) { - var __c18 = body; - for (var __i18 = 0; __i18 < __c18.length; ++__i18) { - var node = __c18[__i18]; + var __c19 = body; + for (var __i19 = 0; __i19 < __c19.length; ++__i19) { + var node = __c19[__i19]; this.compile(node); } } @@ -6644,9 +6669,9 @@ Compiler.prototype.compile_function = function(node) { viml_remove(rlist, -1); var remaining = TRUE; } - var __c19 = viml_range(viml_len(rlist)); - for (var __i19 = 0; __i19 < __c19.length; ++__i19) { - var i = __c19[__i19]; + var __c20 = viml_range(viml_len(rlist)); + for (var __i20 = 0; __i20 < __c20.length; ++__i20) { + var i = __c20[__i20]; if (i < viml_len(rlist) - viml_len(default_args)) { left += viml_printf(" %s", rlist[i]); } @@ -6765,9 +6790,9 @@ Compiler.prototype.compile_if = function(node) { this.incindent(" "); this.compile_body(node.body); this.decindent(); - var __c20 = node.elseif; - for (var __i20 = 0; __i20 < __c20.length; ++__i20) { - var enode = __c20[__i20]; + var __c21 = node.elseif; + for (var __i21 = 0; __i21 < __c21.length; ++__i21) { + var enode = __c21[__i21]; this.out(" elseif %s", this.compile(enode.cond)); this.incindent(" "); this.compile_body(enode.body); @@ -6824,9 +6849,9 @@ Compiler.prototype.compile_try = function(node) { this.out("(try"); this.incindent(" "); this.compile_body(node.body); - var __c21 = node.catch; - for (var __i21 = 0; __i21 < __c21.length; ++__i21) { - var cnode = __c21[__i21]; + var __c22 = node.catch; + for (var __i22 = 0; __i22 < __c22.length; ++__i22) { + var cnode = __c22[__i22]; if (cnode.pattern !== NIL) { this.decindent(); this.out(" catch /%s/", cnode.pattern); @@ -7168,9 +7193,9 @@ Compiler.prototype.compile_curlynameexpr = function(node) { Compiler.prototype.escape_string = function(str) { var m = {"\n":"\\n", "\t":"\\t", "\r":"\\r"}; var out = "\""; - var __c22 = viml_range(viml_len(str)); - for (var __i22 = 0; __i22 < __c22.length; ++__i22) { - var i = __c22[__i22]; + var __c23 = viml_range(viml_len(str)); + for (var __i23 = 0; __i23 < __c23.length; ++__i23) { + var i = __c23[__i23]; var c = str[i]; if (viml_has_key(m, c)) { out += m[c]; @@ -7192,13 +7217,13 @@ Compiler.prototype.compile_lambda = function(node) { var compiler = new Compiler(); compiler.compile_body(node.body); var body = []; - var __c23 = compiler.lines; - for (var __i23 = 0; __i23 < __c23.length; ++__i23) { - var line = __c23[__i23]; + var __c24 = compiler.lines; + for (var __i24 = 0; __i24 < __c24.length; ++__i24) { + var line = __c24[__i24]; var text = ""; - var __c24 = viml_split(line, "\\zs"); - for (var __i24 = 0; __i24 < __c24.length; ++__i24) { - var c = __c24[__i24]; + var __c25 = viml_split(line, "\\zs"); + for (var __i25 = 0; __i25 < __c25.length; ++__i25) { + var c = __c25[__i25]; if (text != "" || c != " ") { text += c; } @@ -7273,9 +7298,9 @@ Compiler.prototype.compile_def = function(node) { viml_remove(rlist, -1); var remaining = TRUE; } - var __c25 = viml_range(viml_len(rlist)); - for (var __i25 = 0; __i25 < __c25.length; ++__i25) { - var i = __c25[__i25]; + var __c26 = viml_range(viml_len(rlist)); + for (var __i26 = 0; __i26 < __c26.length; ++__i26) { + var i = __c26[__i26]; if (i < viml_len(rlist) - viml_len(default_args)) { left += viml_printf(" %s", rlist[i]); } @@ -7382,9 +7407,9 @@ Compiler.prototype.compile_enum = function(node) { } this.out("(enum %s", s); this.incindent(" "); - var __c26 = node.enumvalues; - for (var __i26 = 0; __i26 < __c26.length; ++__i26) { - var value = __c26[__i26]; + var __c27 = node.enumvalues; + for (var __i27 = 0; __i27 < __c27.length; ++__i27) { + var value = __c27[__i27]; var rlist = value.rlist.map((function(vval) { return this.compile(vval); }).bind(this)); if (viml_empty(rlist)) { this.out("(%s)", value.value); @@ -8093,9 +8118,9 @@ RegexpParser.prototype.get_token_sq_char_class = function() { var r = this.reader.read_alpha(); if (this.reader.p(0) == ":" && this.reader.p(1) == "]") { this.reader.seek_cur(2); - var __c27 = class_names; - for (var __i27 = 0; __i27 < __c27.length; ++__i27) { - var name = __c27[__i27]; + var __c28 = class_names; + for (var __i28 = 0; __i28 < __c28.length; ++__i28) { + var name = __c28[__i28]; if (r == name) { return "[:" + name + ":]"; } @@ -8228,9 +8253,9 @@ RegexpParser.prototype.getoctchrs = function() { RegexpParser.prototype.gethexchrs = function(n) { var r = ""; - var __c28 = viml_range(n); - for (var __i28 = 0; __i28 < __c28.length; ++__i28) { - var i = __c28[__i28]; + var __c29 = viml_range(n); + for (var __i29 = 0; __i29 < __c29.length; ++__i29) { + var i = __c29[__i29]; var c = this.reader.peek(); if (!isxdigit(c)) { break; diff --git a/py/vimlparser.py b/py/vimlparser.py index f9efb29..cdf8b21 100644 --- a/py/vimlparser.py +++ b/py/vimlparser.py @@ -720,15 +720,28 @@ def declare(self, node): self.declared[node.value] = 1 def push_context(self, node): - if node.type == NODE_DEF or node.type == NODE_FUNCTION: + # Functions have their own scope. In Vim9 script a block also has its own + # scope, also at the script level. + if node.type == NODE_DEF or node.type == NODE_FUNCTION or node.type == NODE_BLOCK or self.isvim9() and (node.type == NODE_IF or node.type == NODE_WHILE or node.type == NODE_FOR or node.type == NODE_TRY): self.push_scope() + viml_insert(self.scope_nodes, node) viml_insert(self.context, node) def pop_context(self): - if self.context[0].type == NODE_DEF or self.context[0].type == NODE_FUNCTION: + if not viml_empty(self.scope_nodes) and self.scope_nodes[0] is self.context[0]: self.pop_scope() + viml_remove(self.scope_nodes, 0) viml_remove(self.context, 0) + # Names declared in one branch of :if or :try are not visible in the next + # branch: go back to the names known before the :if or :try. + def reset_branch_scope(self): + if not viml_empty(self.scope_nodes) and self.scope_nodes[0] is self.context[0]: + declared = AttributeDict({}) + for name in viml_keys(self.outer_declared[0]): + declared[name] = 1 + self.declared = declared + # Names declared in a function or lambda are only visible inside it: continue # with a copy of the declared names and restore them with pop_scope(). def push_scope(self): @@ -813,6 +826,8 @@ def parse_toplevel(self, reader): # command. self.declared = AttributeDict({}) self.outer_declared = [] + # Context nodes that started a scope with push_scope(). + self.scope_nodes = [] # Names in :def functions that were not declared when they were parsed. self.undeclared_in_def = AttributeDict({}) self.push_context(toplevel) @@ -2726,6 +2741,7 @@ def parse_cmd_elseif(self): raise VimLParserException(Err("E582: :elseif without :if", self.ea.cmdpos)) if self.context[0].type != NODE_IF: self.pop_context() + self.reset_branch_scope() node = Node(NODE_ELSEIF) node.pos = self.ea.cmdpos node.body = [] @@ -2739,6 +2755,7 @@ def parse_cmd_else(self): raise VimLParserException(Err("E581: :else without :if", self.ea.cmdpos)) if self.context[0].type != NODE_IF: self.pop_context() + self.reset_branch_scope() node = Node(NODE_ELSE) node.pos = self.ea.cmdpos node.body = [] @@ -2791,11 +2808,6 @@ def parse_cmd_for(self): node.left = lhs.left node.list = lhs.list node.rest = lhs.rest - self.declare(node.left) - if node.list is not NIL: - for x in node.list: - self.declare(x) - self.declare(node.rest) self.reader.skip_white() epos = self.reader.getpos() if self.reader.read_alpha() != "in": @@ -2803,6 +2815,12 @@ def parse_cmd_for(self): node.right = self.parse_expr() self.add_node(node) self.push_context(node) + # The loop variables are only visible inside the loop in Vim9 script. + self.declare(node.left) + if node.list is not NIL: + for x in node.list: + self.declare(x) + self.declare(node.rest) # Vim9 :for loop variables with optional types: "name: type" or # "[name: type, ...]" @@ -2871,6 +2889,7 @@ def parse_cmd_catch(self): raise VimLParserException(Err("E603: :catch without :try", self.ea.cmdpos)) if self.context[0].type != NODE_TRY: self.pop_context() + self.reset_branch_scope() node = Node(NODE_CATCH) node.pos = self.ea.cmdpos node.body = [] @@ -2887,6 +2906,7 @@ def parse_cmd_finally(self): raise VimLParserException(Err("E606: :finally without :try", self.ea.cmdpos)) if self.context[0].type != NODE_TRY: self.pop_context() + self.reset_branch_scope() node = Node(NODE_FINALLY) node.pos = self.ea.cmdpos node.body = [] diff --git a/test/test_vim9declared_block.ok b/test/test_vim9declared_block.ok new file mode 100644 index 0000000..ba57706 --- /dev/null +++ b/test/test_vim9declared_block.ok @@ -0,0 +1,31 @@ +(vim9script) +(if true + (var = put 1) + (assign = put 2)) +(excmd "put = 3") +(def (F) + (if false + (var = file 1) + elseif true + (excmd "file = 2") + else + (var = file 3) + (assign = file 4)) + (for edit (list 1) + (echo edit)) + (excmd "edit = 6") + (try + (var = new 1) + catch + (excmd "new = 7") + finally + (excmd "new = 8")) + (block + (var = file 1) + (if true + (assign = file 9))) + (excmd "file = 10") + (while true + (var = put 1) + (break)) + (excmd "put = 11")) diff --git a/test/test_vim9declared_block.vim b/test/test_vim9declared_block.vim new file mode 100644 index 0000000..06a4870 --- /dev/null +++ b/test/test_vim9declared_block.vim @@ -0,0 +1,39 @@ +vim9script +if true + var put = 1 + put = 2 +endif +put = 3 +def F() + if false + var file = 1 + elseif true + file = 2 + else + var file = 3 + file = 4 + endif + for edit in [1] + echo edit + endfor + edit = 6 + try + var new = 1 + catch + new = 7 + finally + new = 8 + endtry + { + var file = 1 + if true + file = 9 + endif + } + file = 10 + while true + var put = 1 + break + endwhile + put = 11 +enddef