diff --git a/src/lcode.c b/src/lcode.c index 216b0f7..3a28761 100644 --- a/src/lcode.c +++ b/src/lcode.c @@ -1278,7 +1278,17 @@ static void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) { e->u.info = luaK_codeABC(fs, OP_LEN, 0, r, 0); if (e->ravi_type == RAVI_TARRAYINT || e->ravi_type == RAVI_TARRAYFLT || e->ravi_type == RAVI_TSTRING) { e->ravi_type = RAVI_TNUMINT; - } else { + } else if(e->ravi_type == RAVI_TTABLE) { + e->k = VRELOCABLE; + luaK_exp2anyreg(fs, e); + /* This is not incompatible with lua since a type annotation is require to get here or the table trivially has + * no metatable */ + luaK_codeABC(fs, OP_RAVI_TOINT, e->u.info, 0, 0); + e->ravi_type = RAVI_TNUMINT; + luaK_fixline(fs, line); + return; + } + else { e->ravi_type = RAVI_TANY; } break; diff --git a/tests/language/ravi_tests1.ravi b/tests/language/ravi_tests1.ravi index 0512729..22f1e0e 100644 --- a/tests/language/ravi_tests1.ravi +++ b/tests/language/ravi_tests1.ravi @@ -1523,7 +1523,7 @@ print 'Test 58 OK' function x(s1: string, s2: string) return @string( s1 .. s2 ) end -check(x, 'TOSTRING', 'TOSTRING', 'MOVE', 'MOVE', 'CONCAT', 'TOSTRING', 'RETURN', 'RETURN') +check(x, 'TOSTRING', 'TOSTRING', 'MOVE', 'MOVE', 'CONCAT', 'RETURN', 'RETURN') assert(x('a', 'b') == 'ab') compile(x) assert(x('a', 'b') == 'ab') @@ -1699,8 +1699,8 @@ function x() end assert(ravitype(x()) == 'number[]') assert(x()[1] == 42.0) -check(x, 'NEW_IARRAY', 'LOADK', 'SETLIST', 'TEST', - 'JMP', 'NEW_FARRAY', 'LOADK', 'SETLIST', 'TOFARRAY', +check(x, 'NEW_IARRAY', 'LOADK', 'SETLIST', + 'NEW_FARRAY', 'LOADK', 'SETLIST', 'RETURN', 'RETURN') print 'Test 74 OK' @@ -1797,10 +1797,14 @@ print 'Test 83 OK' function x(x:number) return (~x)+1 end -check(x, 'TOFLT', 'BNOT', 'ADD', 'RETURN', 'RETURN') +check(x, 'TOFLT', 'BNOT', 'ADDII', 'RETURN', 'RETURN') assert(x(1.0) == -1) compile(x) assert(x(1.0) == -1) +function x(x:table) + return (~x)+1 +end +check(x, 'TOTAB', 'BNOT', 'ADD', 'RETURN', 'RETURN') print 'Test 84 OK' -- Test that #() applied to non integer type produces any type