errors.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. -- $Id: testes/errors.lua $
  2. -- See Copyright Notice in file all.lua
  3. print("testing errors")
  4. local debug = require"debug"
  5. -- avoid problems with 'strict' module (which may generate other error messages)
  6. local mt = getmetatable(_G) or {}
  7. local oldmm = mt.__index
  8. mt.__index = nil
  9. local function checkerr (msg, f, ...)
  10. local st, err = pcall(f, ...)
  11. assert(not st and string.find(err, msg))
  12. end
  13. local function doit (s)
  14. local f, msg = load(s)
  15. if not f then return msg end
  16. local cond, msg = pcall(f)
  17. return (not cond) and msg
  18. end
  19. local function checkmessage (prog, msg, debug)
  20. local m = doit(prog)
  21. if debug then print(m, msg) end
  22. assert(string.find(m, msg, 1, true))
  23. end
  24. local function checksyntax (prog, extra, token, line)
  25. local msg = doit(prog)
  26. if not string.find(token, "^<%a") and not string.find(token, "^char%(")
  27. then token = "'"..token.."'" end
  28. token = string.gsub(token, "(%p)", "%%%1")
  29. local pt = string.format([[^%%[string ".*"%%]:%d: .- near %s$]],
  30. line, token)
  31. assert(string.find(msg, pt))
  32. assert(string.find(msg, msg, 1, true))
  33. end
  34. -- test error message with no extra info
  35. assert(doit("error('hi', 0)") == 'hi')
  36. -- test error message with no info
  37. assert(doit("error()") == nil)
  38. -- test common errors/errors that crashed in the past
  39. assert(doit("table.unpack({}, 1, n=2^30)"))
  40. assert(doit("a=math.sin()"))
  41. assert(not doit("tostring(1)") and doit("tostring()"))
  42. assert(doit"tonumber()")
  43. assert(doit"repeat until 1; a")
  44. assert(doit"return;;")
  45. assert(doit"assert(false)")
  46. assert(doit"assert(nil)")
  47. assert(doit("function a (... , ...) end"))
  48. assert(doit("function a (, ...) end"))
  49. assert(doit("local t={}; t = t[#t] + 1"))
  50. checksyntax([[
  51. local a = {4
  52. ]], "'}' expected (to close '{' at line 1)", "<eof>", 3)
  53. do -- testing errors in goto/break
  54. local function checksyntax (prog, msg, line)
  55. local st, err = load(prog)
  56. assert(string.find(err, "line " .. line))
  57. assert(string.find(err, msg, 1, true))
  58. end
  59. checksyntax([[
  60. ::A:: a = 1
  61. ::A::
  62. ]], "label 'A' already defined", 1)
  63. checksyntax([[
  64. a = 1
  65. goto A
  66. do ::A:: end
  67. ]], "no visible label 'A'", 2)
  68. end
  69. if not T then
  70. (Message or print)
  71. ('\n >>> testC not active: skipping memory message test <<<\n')
  72. else
  73. print "testing memory error message"
  74. local a = {}
  75. for i = 1, 10000 do a[i] = true end -- preallocate array
  76. collectgarbage()
  77. T.totalmem(T.totalmem() + 10000)
  78. -- force a memory error (by a small margin)
  79. local st, msg = pcall(function()
  80. for i = 1, 100000 do a[i] = tostring(i) end
  81. end)
  82. T.totalmem(0)
  83. assert(not st and msg == "not enough" .. " memory")
  84. end
  85. -- tests for better error messages
  86. checkmessage("a = {} + 1", "arithmetic")
  87. checkmessage("a = {} | 1", "bitwise operation")
  88. checkmessage("a = {} < 1", "attempt to compare")
  89. checkmessage("a = {} <= 1", "attempt to compare")
  90. checkmessage("a=1; bbbb=2; a=math.sin(3)+bbbb(3)", "global 'bbbb'")
  91. checkmessage("a={}; do local a=1 end a:bbbb(3)", "method 'bbbb'")
  92. checkmessage("local a={}; a.bbbb(3)", "field 'bbbb'")
  93. assert(not string.find(doit"a={13}; local bbbb=1; a[bbbb](3)", "'bbbb'"))
  94. checkmessage("a={13}; local bbbb=1; a[bbbb](3)", "number")
  95. checkmessage("a=(1)..{}", "a table value")
  96. -- calls
  97. checkmessage("local a; a(13)", "local 'a'")
  98. checkmessage([[
  99. local a = setmetatable({}, {__add = 34})
  100. a = a + 1
  101. ]], "metamethod 'add'")
  102. checkmessage([[
  103. local a = setmetatable({}, {__lt = {}})
  104. a = a > a
  105. ]], "metamethod 'lt'")
  106. -- tail calls
  107. checkmessage("local a={}; return a.bbbb(3)", "field 'bbbb'")
  108. checkmessage("a={}; do local a=1 end; return a:bbbb(3)", "method 'bbbb'")
  109. checkmessage("a = #print", "length of a function value")
  110. checkmessage("a = #3", "length of a number value")
  111. aaa = nil
  112. checkmessage("aaa.bbb:ddd(9)", "global 'aaa'")
  113. checkmessage("local aaa={bbb=1}; aaa.bbb:ddd(9)", "field 'bbb'")
  114. checkmessage("local aaa={bbb={}}; aaa.bbb:ddd(9)", "method 'ddd'")
  115. checkmessage("local a,b,c; (function () a = b+1.1 end)()", "upvalue 'b'")
  116. assert(not doit"local aaa={bbb={ddd=next}}; aaa.bbb:ddd(nil)")
  117. -- upvalues being indexed do not go to the stack
  118. checkmessage("local a,b,cc; (function () a = cc[1] end)()", "upvalue 'cc'")
  119. checkmessage("local a,b,cc; (function () a.x = 1 end)()", "upvalue 'a'")
  120. checkmessage("local _ENV = {x={}}; a = a + 1", "global 'a'")
  121. checkmessage("b=1; local aaa={}; x=aaa+b", "local 'aaa'")
  122. checkmessage("aaa={}; x=3.3/aaa", "global 'aaa'")
  123. checkmessage("aaa=2; b=nil;x=aaa*b", "global 'b'")
  124. checkmessage("aaa={}; x=-aaa", "global 'aaa'")
  125. -- short circuit
  126. checkmessage("a=1; local a,bbbb=2,3; a = math.sin(1) and bbbb(3)",
  127. "local 'bbbb'")
  128. checkmessage("a=1; local a,bbbb=2,3; a = bbbb(1) or a(3)", "local 'bbbb'")
  129. checkmessage("local a,b,c,f = 1,1,1; f((a and b) or c)", "local 'f'")
  130. checkmessage("local a,b,c = 1,1,1; ((a and b) or c)()", "call a number value")
  131. assert(not string.find(doit"aaa={}; x=(aaa or aaa)+(aaa and aaa)", "'aaa'"))
  132. assert(not string.find(doit"aaa={}; (aaa or aaa)()", "'aaa'"))
  133. checkmessage("print(print < 10)", "function with number")
  134. checkmessage("print(print < print)", "two function values")
  135. checkmessage("print('10' < 10)", "string with number")
  136. checkmessage("print(10 < '23')", "number with string")
  137. -- float->integer conversions
  138. checkmessage("local a = 2.0^100; x = a << 2", "local a")
  139. checkmessage("local a = 1 >> 2.0^100", "has no integer representation")
  140. checkmessage("local a = 10.1 << 2.0^100", "has no integer representation")
  141. checkmessage("local a = 2.0^100 & 1", "has no integer representation")
  142. checkmessage("local a = 2.0^100 & 1e100", "has no integer representation")
  143. checkmessage("local a = 2.0 | 1e40", "has no integer representation")
  144. checkmessage("local a = 2e100 ~ 1", "has no integer representation")
  145. checkmessage("string.sub('a', 2.0^100)", "has no integer representation")
  146. checkmessage("string.rep('a', 3.3)", "has no integer representation")
  147. checkmessage("return 6e40 & 7", "has no integer representation")
  148. checkmessage("return 34 << 7e30", "has no integer representation")
  149. checkmessage("return ~-3e40", "has no integer representation")
  150. checkmessage("return ~-3.009", "has no integer representation")
  151. checkmessage("return 3.009 & 1", "has no integer representation")
  152. checkmessage("return 34 >> {}", "table value")
  153. checkmessage("a = 24 // 0", "divide by zero")
  154. checkmessage("a = 1 % 0", "'n%0'")
  155. -- type error for an object which is neither in an upvalue nor a register.
  156. -- The following code will try to index the value 10 that is stored in
  157. -- the metatable, without moving it to a register.
  158. checkmessage("local a = setmetatable({}, {__index = 10}).x",
  159. "attempt to index a number value")
  160. -- numeric for loops
  161. checkmessage("for i = {}, 10 do end", "table")
  162. checkmessage("for i = io.stdin, 10 do end", "FILE")
  163. checkmessage("for i = {}, 10 do end", "initial value")
  164. checkmessage("for i = 1, 'x', 10 do end", "string")
  165. checkmessage("for i = 1, {}, 10 do end", "limit")
  166. checkmessage("for i = 1, {} do end", "limit")
  167. checkmessage("for i = 1, 10, print do end", "step")
  168. checkmessage("for i = 1, 10, print do end", "function")
  169. -- passing light userdata instead of full userdata
  170. _G.D = debug
  171. checkmessage([[
  172. -- create light udata
  173. local x = D.upvalueid(function () return debug end, 1)
  174. D.setuservalue(x, {})
  175. ]], "light userdata")
  176. _G.D = nil
  177. do -- named objects (field '__name')
  178. checkmessage("math.sin(io.input())", "(number expected, got FILE*)")
  179. _G.XX = setmetatable({}, {__name = "My Type"})
  180. assert(string.find(tostring(XX), "^My Type"))
  181. checkmessage("io.input(XX)", "(FILE* expected, got My Type)")
  182. checkmessage("return XX + 1", "on a My Type value")
  183. checkmessage("return ~io.stdin", "on a FILE* value")
  184. checkmessage("return XX < XX", "two My Type values")
  185. checkmessage("return {} < XX", "table with My Type")
  186. checkmessage("return XX < io.stdin", "My Type with FILE*")
  187. _G.XX = nil
  188. if T then -- extra tests for 'luaL_tolstring'
  189. -- bug in 5.4.3; 'luaL_tolstring' with negative indices
  190. local x = setmetatable({}, {__name="TABLE"})
  191. assert(T.testC("Ltolstring -1; return 1", x) == tostring(x))
  192. local a, b = T.testC("pushint 10; Ltolstring -2; return 2", x)
  193. assert(a == 10 and b == tostring(x))
  194. setmetatable(x, {__tostring=function (o)
  195. assert(o == x)
  196. return "ABC"
  197. end})
  198. local a, b, c = T.testC("pushint 10; Ltolstring -2; return 3", x)
  199. assert(a == x and b == 10 and c == "ABC")
  200. end
  201. end
  202. -- global functions
  203. checkmessage("(io.write or print){}", "io.write")
  204. checkmessage("(collectgarbage or print){}", "collectgarbage")
  205. -- errors in functions without debug info
  206. do
  207. local f = function (a) return a + 1 end
  208. f = assert(load(string.dump(f, true)))
  209. assert(f(3) == 4)
  210. checkerr("^%?:%-1:", f, {})
  211. -- code with a move to a local var ('OP_MOV A B' with A<B)
  212. f = function () local a; a = {}; return a + 2 end
  213. -- no debug info (so that 'a' is unknown)
  214. f = assert(load(string.dump(f, true)))
  215. -- symbolic execution should not get lost
  216. checkerr("^%?:%-1:.*table value", f)
  217. end
  218. -- tests for field accesses after RK limit
  219. local t = {}
  220. for i = 1, 1000 do
  221. t[i] = "a = x" .. i
  222. end
  223. local s = table.concat(t, "; ")
  224. t = nil
  225. checkmessage(s.."; a = bbb + 1", "global 'bbb'")
  226. checkmessage("local _ENV=_ENV;"..s.."; a = bbb + 1", "global 'bbb'")
  227. checkmessage(s.."; local t = {}; a = t.bbb + 1", "field 'bbb'")
  228. checkmessage(s.."; local t = {}; t:bbb()", "method 'bbb'")
  229. checkmessage([[aaa=9
  230. repeat until 3==3
  231. local x=math.sin(math.cos(3))
  232. if math.sin(1) == x then return math.sin(1) end -- tail call
  233. local a,b = 1, {
  234. {x='a'..'b'..'c', y='b', z=x},
  235. {1,2,3,4,5} or 3+3<=3+3,
  236. 3+1>3+1,
  237. {d = x and aaa[x or y]}}
  238. ]], "global 'aaa'")
  239. checkmessage([[
  240. local x,y = {},1
  241. if math.sin(1) == 0 then return 3 end -- return
  242. x.a()]], "field 'a'")
  243. checkmessage([[
  244. prefix = nil
  245. insert = nil
  246. while 1 do
  247. local a
  248. if nil then break end
  249. insert(prefix, a)
  250. end]], "global 'insert'")
  251. checkmessage([[ -- tail call
  252. return math.sin("a")
  253. ]], "sin")
  254. checkmessage([[collectgarbage("nooption")]], "invalid option")
  255. checkmessage([[x = print .. "a"]], "concatenate")
  256. checkmessage([[x = "a" .. false]], "concatenate")
  257. checkmessage([[x = {} .. 2]], "concatenate")
  258. checkmessage("getmetatable(io.stdin).__gc()", "no value")
  259. checkmessage([[
  260. local Var
  261. local function main()
  262. NoSuchName (function() Var=0 end)
  263. end
  264. main()
  265. ]], "global 'NoSuchName'")
  266. print'+'
  267. a = {}; setmetatable(a, {__index = string})
  268. checkmessage("a:sub()", "bad self")
  269. checkmessage("string.sub('a', {})", "#2")
  270. checkmessage("('a'):sub{}", "#1")
  271. checkmessage("table.sort({1,2,3}, table.sort)", "'table.sort'")
  272. checkmessage("string.gsub('s', 's', setmetatable)", "'setmetatable'")
  273. -- tests for errors in coroutines
  274. local function f (n)
  275. local c = coroutine.create(f)
  276. local a,b = coroutine.resume(c)
  277. return b
  278. end
  279. assert(string.find(f(), "C stack overflow"))
  280. checkmessage("coroutine.yield()", "outside a coroutine")
  281. f = coroutine.wrap(function () table.sort({1,2,3}, coroutine.yield) end)
  282. checkerr("yield across", f)
  283. -- testing size of 'source' info; size of buffer for that info is
  284. -- LUA_IDSIZE, declared as 60 in luaconf. Get one position for '\0'.
  285. idsize = 60 - 1
  286. local function checksize (source)
  287. -- syntax error
  288. local _, msg = load("x", source)
  289. msg = string.match(msg, "^([^:]*):") -- get source (1st part before ':')
  290. assert(msg:len() <= idsize)
  291. end
  292. for i = 60 - 10, 60 + 10 do -- check border cases around 60
  293. checksize("@" .. string.rep("x", i)) -- file names
  294. checksize(string.rep("x", i - 10)) -- string sources
  295. checksize("=" .. string.rep("x", i)) -- exact sources
  296. end
  297. -- testing line error
  298. local function lineerror (s, l)
  299. local err,msg = pcall(load(s))
  300. local line = tonumber(string.match(msg, ":(%d+):"))
  301. assert(line == l or (not line and not l))
  302. end
  303. lineerror("local a\n for i=1,'a' do \n print(i) \n end", 2)
  304. lineerror("\n local a \n for k,v in 3 \n do \n print(k) \n end", 3)
  305. lineerror("\n\n for k,v in \n 3 \n do \n print(k) \n end", 4)
  306. lineerror("function a.x.y ()\na=a+1\nend", 1)
  307. lineerror("a = \na\n+\n{}", 3)
  308. lineerror("a = \n3\n+\n(\n4\n/\nprint)", 6)
  309. lineerror("a = \nprint\n+\n(\n4\n/\n7)", 3)
  310. lineerror("a\n=\n-\n\nprint\n;", 3)
  311. lineerror([[
  312. a
  313. (
  314. 23)
  315. ]], 1)
  316. lineerror([[
  317. local a = {x = 13}
  318. a
  319. .
  320. x
  321. (
  322. 23
  323. )
  324. ]], 2)
  325. lineerror([[
  326. local a = {x = 13}
  327. a
  328. .
  329. x
  330. (
  331. 23 + a
  332. )
  333. ]], 6)
  334. local p = [[
  335. function g() f() end
  336. function f(x) error('a', X) end
  337. g()
  338. ]]
  339. X=3;lineerror((p), 3)
  340. X=0;lineerror((p), false)
  341. X=1;lineerror((p), 2)
  342. X=2;lineerror((p), 1)
  343. lineerror([[
  344. local b = false
  345. if not b then
  346. error 'test'
  347. end]], 3)
  348. lineerror([[
  349. local b = false
  350. if not b then
  351. if not b then
  352. if not b then
  353. error 'test'
  354. end
  355. end
  356. end]], 5)
  357. do
  358. -- Force a negative estimate for base line. Error in instruction 2
  359. -- (after VARARGPREP, GETGLOBAL), with first absolute line information
  360. -- (forced by too many lines) in instruction 0.
  361. local s = string.format("%s return __A.x", string.rep("\n", 300))
  362. lineerror(s, 301)
  363. end
  364. if not _soft then
  365. -- several tests that exaust the Lua stack
  366. collectgarbage()
  367. print"testing stack overflow"
  368. C = 0
  369. -- get line where stack overflow will happen
  370. local l = debug.getinfo(1, "l").currentline + 1
  371. local function auxy () C=C+1; auxy() end -- produce a stack overflow
  372. function y ()
  373. collectgarbage("stop") -- avoid running finalizers without stack space
  374. auxy()
  375. collectgarbage("restart")
  376. end
  377. local function checkstackmessage (m)
  378. print("(expected stack overflow after " .. C .. " calls)")
  379. C = 0 -- prepare next count
  380. return (string.find(m, "stack overflow"))
  381. end
  382. -- repeated stack overflows (to check stack recovery)
  383. assert(checkstackmessage(doit('y()')))
  384. assert(checkstackmessage(doit('y()')))
  385. assert(checkstackmessage(doit('y()')))
  386. -- error lines in stack overflow
  387. local l1
  388. local function g(x)
  389. l1 = debug.getinfo(x, "l").currentline + 2
  390. collectgarbage("stop") -- avoid running finalizers without stack space
  391. auxy()
  392. collectgarbage("restart")
  393. end
  394. local _, stackmsg = xpcall(g, debug.traceback, 1)
  395. print('+')
  396. local stack = {}
  397. for line in string.gmatch(stackmsg, "[^\n]*") do
  398. local curr = string.match(line, ":(%d+):")
  399. if curr then table.insert(stack, tonumber(curr)) end
  400. end
  401. local i=1
  402. while stack[i] ~= l1 do
  403. assert(stack[i] == l)
  404. i = i+1
  405. end
  406. assert(i > 15)
  407. -- error in error handling
  408. local res, msg = xpcall(error, error)
  409. assert(not res and type(msg) == 'string')
  410. print('+')
  411. local function f (x)
  412. if x==0 then error('a\n')
  413. else
  414. local aux = function () return f(x-1) end
  415. local a,b = xpcall(aux, aux)
  416. return a,b
  417. end
  418. end
  419. f(3)
  420. local function loop (x,y,z) return 1 + loop(x, y, z) end
  421. local res, msg = xpcall(loop, function (m)
  422. assert(string.find(m, "stack overflow"))
  423. checkerr("error handling", loop)
  424. assert(math.sin(0) == 0)
  425. return 15
  426. end)
  427. assert(msg == 15)
  428. local f = function ()
  429. for i = 999900, 1000000, 1 do table.unpack({}, 1, i) end
  430. end
  431. checkerr("too many results", f)
  432. end
  433. do
  434. -- non string messages
  435. local t = {}
  436. local res, msg = pcall(function () error(t) end)
  437. assert(not res and msg == t)
  438. res, msg = pcall(function () error(nil) end)
  439. assert(not res and msg == nil)
  440. local function f() error{msg='x'} end
  441. res, msg = xpcall(f, function (r) return {msg=r.msg..'y'} end)
  442. assert(msg.msg == 'xy')
  443. -- 'assert' with extra arguments
  444. res, msg = pcall(assert, false, "X", t)
  445. assert(not res and msg == "X")
  446. -- 'assert' with no message
  447. res, msg = pcall(function () assert(false) end)
  448. local line = string.match(msg, "%w+%.lua:(%d+): assertion failed!$")
  449. assert(tonumber(line) == debug.getinfo(1, "l").currentline - 2)
  450. -- 'assert' with non-string messages
  451. res, msg = pcall(assert, false, t)
  452. assert(not res and msg == t)
  453. res, msg = pcall(assert, nil, nil)
  454. assert(not res and msg == nil)
  455. -- 'assert' without arguments
  456. res, msg = pcall(assert)
  457. assert(not res and string.find(msg, "value expected"))
  458. end
  459. -- xpcall with arguments
  460. a, b, c = xpcall(string.find, error, "alo", "al")
  461. assert(a and b == 1 and c == 2)
  462. a, b, c = xpcall(string.find, function (x) return {} end, true, "al")
  463. assert(not a and type(b) == "table" and c == nil)
  464. print("testing tokens in error messages")
  465. checksyntax("syntax error", "", "error", 1)
  466. checksyntax("1.000", "", "1.000", 1)
  467. checksyntax("[[a]]", "", "[[a]]", 1)
  468. checksyntax("'aa'", "", "'aa'", 1)
  469. checksyntax("while << do end", "", "<<", 1)
  470. checksyntax("for >> do end", "", ">>", 1)
  471. -- test invalid non-printable char in a chunk
  472. checksyntax("a\1a = 1", "", "<\\1>", 1)
  473. -- test 255 as first char in a chunk
  474. checksyntax("\255a = 1", "", "<\\255>", 1)
  475. doit('I = load("a=9+"); a=3')
  476. assert(a==3 and not I)
  477. print('+')
  478. lim = 1000
  479. if _soft then lim = 100 end
  480. for i=1,lim do
  481. doit('a = ')
  482. doit('a = 4+nil')
  483. end
  484. -- testing syntax limits
  485. local function testrep (init, rep, close, repc, finalresult)
  486. local s = init .. string.rep(rep, 100) .. close .. string.rep(repc, 100)
  487. local res, msg = load(s)
  488. assert(res) -- 100 levels is OK
  489. if (finalresult) then
  490. assert(res() == finalresult)
  491. end
  492. s = init .. string.rep(rep, 500)
  493. local res, msg = load(s) -- 500 levels not ok
  494. assert(not res and (string.find(msg, "too many") or
  495. string.find(msg, "overflow")))
  496. end
  497. testrep("local a; a", ",a", "= 1", ",1") -- multiple assignment
  498. testrep("local a; a=", "{", "0", "}")
  499. testrep("return ", "(", "2", ")", 2)
  500. testrep("local function a (x) return x end; return ", "a(", "2.2", ")", 2.2)
  501. testrep("", "do ", "", " end")
  502. testrep("", "while a do ", "", " end")
  503. testrep("local a; ", "if a then else ", "", " end")
  504. testrep("", "function foo () ", "", " end")
  505. testrep("local a = ''; return ", "a..", "'a'", "", "a")
  506. testrep("local a = 1; return ", "a^", "a", "", 1)
  507. checkmessage("a = f(x" .. string.rep(",x", 260) .. ")", "too many registers")
  508. -- testing other limits
  509. -- upvalues
  510. local lim = 127
  511. local s = "local function fooA ()\n local "
  512. for j = 1,lim do
  513. s = s.."a"..j..", "
  514. end
  515. s = s.."b,c\n"
  516. s = s.."local function fooB ()\n local "
  517. for j = 1,lim do
  518. s = s.."b"..j..", "
  519. end
  520. s = s.."b\n"
  521. s = s.."function fooC () return b+c"
  522. local c = 1+2
  523. for j = 1,lim do
  524. s = s.."+a"..j.."+b"..j
  525. c = c + 2
  526. end
  527. s = s.."\nend end end"
  528. local a,b = load(s)
  529. assert(c > 255 and string.find(b, "too many upvalues") and
  530. string.find(b, "line 5"))
  531. -- local variables
  532. s = "\nfunction foo ()\n local "
  533. for j = 1,300 do
  534. s = s.."a"..j..", "
  535. end
  536. s = s.."b\n"
  537. local a,b = load(s)
  538. assert(string.find(b, "line 2") and string.find(b, "too many local variables"))
  539. mt.__index = oldmm
  540. print('OK')