Mercurial > vim
comparison src/testdir/test_vim9_builtin.vim @ 30576:72e6073a2822 v9.0.0623
patch 9.0.0623: error for modifying a const is not detected at compile time
Commit: https://github.com/vim/vim/commit/fa1039760e8c1a0c7a2a722160bd3d71a4736e61
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 29 19:14:42 2022 +0100
patch 9.0.0623: error for modifying a const is not detected at compile time
Problem: Error for modifying a const is not detected at compile time.
Solution: Add TTFLAG_CONST and check for it in add() and extend().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 29 Sep 2022 20:15:05 +0200 |
parents | b4c9540577cf |
children | ee039a6049ff |
comparison
equal
deleted
inserted
replaced
30575:3b314751334b | 30576:72e6073a2822 |
---|---|
181 var l: list<string> | 181 var l: list<string> |
182 l->add(123) | 182 l->add(123) |
183 END | 183 END |
184 v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got number', 3) | 184 v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got number', 3) |
185 enddef | 185 enddef |
186 | |
187 def Test_add_const() | |
188 var lines =<< trim END | |
189 const l = [1, 2] | |
190 add(l, 3) | |
191 END | |
192 v9.CheckDefFailure(lines, 'E1307: Argument 1: Trying to modify a const list<number>') | |
193 | |
194 lines =<< trim END | |
195 const b = 0z0102 | |
196 add(b, 0z03) | |
197 END | |
198 v9.CheckDefFailure(lines, 'E1307: Argument 1: Trying to modify a const blob') | |
199 enddef | |
200 | |
186 | 201 |
187 def Test_and() | 202 def Test_and() |
188 v9.CheckDefAndScriptFailure(['and("x", 0x2)'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1']) | 203 v9.CheckDefAndScriptFailure(['and("x", 0x2)'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1']) |
189 v9.CheckDefAndScriptFailure(['and(0x1, "x")'], ['E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2']) | 204 v9.CheckDefAndScriptFailure(['and(0x1, "x")'], ['E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2']) |
190 enddef | 205 enddef |
1177 enddef | 1192 enddef |
1178 | 1193 |
1179 Test() | 1194 Test() |
1180 END | 1195 END |
1181 v9.CheckScriptFailure(lines, 'E1001: Variable not found: m') | 1196 v9.CheckScriptFailure(lines, 'E1001: Variable not found: m') |
1197 enddef | |
1198 | |
1199 def Test_extend_const() | |
1200 var lines =<< trim END | |
1201 const l = [1, 2] | |
1202 extend(l, [3]) | |
1203 END | |
1204 v9.CheckDefFailure(lines, 'E1307: Argument 1: Trying to modify a const list<number>') | |
1205 | |
1206 lines =<< trim END | |
1207 const d = {a: 1, b: 2} | |
1208 extend(d, {c: 3}) | |
1209 END | |
1210 v9.CheckDefFailure(lines, 'E1307: Argument 1: Trying to modify a const dict<number>') | |
1211 | |
1212 # item in a for loop is const | |
1213 lines =<< trim END | |
1214 var l: list<dict<any>> = [{n: 1}] | |
1215 for item in l | |
1216 item->extend({x: 2}) | |
1217 endfor | |
1218 END | |
1219 v9.CheckDefFailure(lines, 'E1307: Argument 1: Trying to modify a const dict<any>') | |
1182 enddef | 1220 enddef |
1183 | 1221 |
1184 def Test_extendnew() | 1222 def Test_extendnew() |
1185 assert_equal([1, 2, 'a'], extendnew([1, 2], ['a'])) | 1223 assert_equal([1, 2, 'a'], extendnew([1, 2], ['a'])) |
1186 assert_equal({one: 1, two: 'a'}, extendnew({one: 1}, {two: 'a'})) | 1224 assert_equal({one: 1, two: 'a'}, extendnew({one: 1}, {two: 'a'})) |