Browse Source

Don't generate op_inc whenever its used as an expression.

Jeff Hutchinson 4 years ago
parent
commit
55c0a748b4
2 changed files with 15 additions and 1 deletions
  1. 1 1
      Engine/source/console/astNodes.cpp
  2. 14 0
      Engine/source/console/test/ScriptTest.cpp

+ 1 - 1
Engine/source/console/astNodes.cpp

@@ -1083,7 +1083,7 @@ U32 AssignOpExprNode::compile(CodeStream& codeStream, U32 ip, TypeReq type)
 
    bool oldVariables = arrayIndex || varName[0] == '$';
 
-   if (op == opPLUSPLUS && !oldVariables)
+   if (op == opPLUSPLUS && !oldVariables && type == TypeReqNone)
    {
       const S32 varIdx = getFuncVars(dbgLineNumber)->assign(varName, TypeReqFloat, dbgLineNumber);
 

+ 14 - 0
Engine/source/console/test/ScriptTest.cpp

@@ -968,6 +968,20 @@ TEST(Script, MiscRegressions)
    )");
    
    ASSERT_EQ(regression4.getFloat(), 0.5);
+
+   Con::setBoolVariable("$Debug::DumpByteCode", true);
+
+   ConsoleValue regression5 = RunScript(R"(
+      function noOpInc()
+      {
+         %count = 0;
+         %var[%count++] = 2;
+         return %var[1];
+      }
+      return noOpInc();
+   )");
+
+   ASSERT_EQ(regression5.getInt(), 2);
 }
 
 #endif