From 5081ed176da82e2bb260fa4f6db736655d3609da Mon Sep 17 00:00:00 2001 From: Sainan Date: Tue, 16 May 2023 20:37:18 +0200 Subject: [PATCH] Support ++ statement for table properties --- src/lparser.cpp | 11 +++++++---- tests/basic.pluto | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lparser.cpp b/src/lparser.cpp index 83308807f9..0bb4adff59 100644 --- a/src/lparser.cpp +++ b/src/lparser.cpp @@ -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 */ @@ -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' */ @@ -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 */ diff --git a/tests/basic.pluto b/tests/basic.pluto index 915cc861cf..11c34d99a3 100644 --- a/tests/basic.pluto +++ b/tests/basic.pluto @@ -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."