issue #62 if integer[] or number[] local is not initialized then raise error

pull/81/head
Dibyendu Majumdar 9 years ago
parent f88ffb1004
commit 7c037ec330

@ -54,7 +54,8 @@ checkmessage('local t: integer[] = {}; local x=function() return 0 end; local f=
checkmessage('local t: integer[] = {}; local x=function() t[1] = 1; local f=function() t = 1 end; f(); end; x()', 'upvalue of integer[] type, cannot be set to non integer[] value')
checkmessage('local t: integer[] = {false}', 'value cannot be converted to integer')
checkmessage('local x=function() return "hi" end; local t: integer[] = {x()}', 'value cannot be converted to integer')
checkmessage('local x=function() return "hi" end; local t: integer[]; t[1] = x()', 'integer expected')
checkmessage('local x=function() return "hi" end; local t: integer[] = {}; t[1] = x()', 'integer expected')
checkmessage('local i: integer, t: integer[], j: number', 'uninitialized integer[] local variable')
checkmessage('local t: number[] = {}; local t2: number[] = {1.0}; t=t2[1]', 'Invalid assignment: number[] expected')
checkmessage('local t: number[] = {}; t=1', 'Invalid assignment: number[] expected')
@ -69,4 +70,5 @@ checkmessage('local t: number[] = {}; local x=function() return 0 end; local f=f
checkmessage('local t: number[] = {}; local x=function() t[1] = 1; local f=function() t = 1 end; f(); end; x()', 'upvalue of number[] type, cannot be set to non number[] value')
checkmessage('local t: number[] = {false}', 'value cannot be converted to number')
checkmessage('local x=function() return "hi" end; local t: number[] = {x()}', 'value cannot be converted to number')
checkmessage('local x=function() return "hi" end; local t: number[]; t[1] = x()', 'number expected')
checkmessage('local x=function() return "hi" end; local t: number[] = {}; t[1] = x()', 'number expected')
checkmessage('local i: integer, t: number[], j: number', 'uninitialized number[] local variable')

@ -581,6 +581,10 @@ static void ravi_code_setzero(FuncState *fs, int reg, ravitype_t ravi_type) {
if (ravi_type == RAVI_TNUMFLT || ravi_type == RAVI_TNUMINT)
/* code an instruction to convert in place */
luaK_codeABC(fs, ravi_type == RAVI_TNUMFLT ? OP_RAVI_LOADFZ : OP_RAVI_LOADIZ, reg, 0, 0);
else if (ravi_type == RAVI_TARRAYFLT)
luaX_syntaxerror(fs->ls, "uninitialized number[] local variable");
else if (ravi_type == RAVI_TARRAYINT)
luaX_syntaxerror(fs->ls, "uninitialized integer[] local variable");
}

Loading…
Cancel
Save