Skip to content

Commit

Permalink
Support ++ statement for table properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed May 23, 2023
1 parent 32bf830 commit 5081ed1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2745,10 +2745,13 @@ static BinOpr getbinopr (int op) {
}


static void prefixplusplus (LexState *ls, expdesc *v) {
static void prefixplusplus (LexState *ls, expdesc *v, bool as_statement) {
int line = ls->getLineNumber();
luaX_next(ls); /* skip second '+' */
singlevar(ls, v); /* variable name */
if (as_statement)
suffixedexp(ls, v);
else
singlevar(ls, v); /* variable name */
FuncState *fs = ls->fs;
expdesc e = *v, v2;
if (v->k != VLOCAL) { /* complex lvalue, use a temporary register. linear perf incr. with complexity of lvalue */
Expand Down Expand Up @@ -2818,7 +2821,7 @@ static BinOpr subexpr (LexState *ls, expdesc *v, int limit, TypeDesc *prop = nul
int line = ls->getLineNumber();
luaX_next(ls); /* skip '+' */
if (ls->t.token == '+') { /* '++' ? */
prefixplusplus(ls, v);
prefixplusplus(ls, v, false);
}
else {
/* support pseudo-unary '+' by implying '0 + subexpr' */
Expand Down Expand Up @@ -4269,7 +4272,7 @@ static void statement (LexState *ls, TypeDesc *prop) {
luaX_next(ls);
check(ls, '+');
expdesc v;
prefixplusplus(ls, &v);
prefixplusplus(ls, &v, true);
break;
}
default: { /* stat -> func | assignment */
Expand Down
4 changes: 4 additions & 0 deletions tests/basic.pluto
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,10 @@ do
local a = 1
++a
assert(a == 2)

local t = { a = 1 }
++t.a
assert(t.a == 2)
end

print "Testing non-ascii variable names."
Expand Down

0 comments on commit 5081ed1

Please sign in to comment.