diff --git a/Engine/source/console/torquescript/astNodes.cpp b/Engine/source/console/torquescript/astNodes.cpp index 8e786cf14..fcf2b69c2 100644 --- a/Engine/source/console/torquescript/astNodes.cpp +++ b/Engine/source/console/torquescript/astNodes.cpp @@ -1370,7 +1370,7 @@ U32 SlotAssignOpNode::compile(CodeStream& codeStream, U32 ip, TypeReq type) if (arrayExpr) { codeStream.emit(OP_SETCURFIELD_ARRAY); - if (subType == TypeReqNone) + if (subType == TypeReqNone || type == TypeReqNone) codeStream.emit(OP_POP_STK); } codeStream.emit((subType == TypeReqFloat) ? OP_LOADFIELD_FLT : OP_LOADFIELD_UINT); diff --git a/Engine/source/testing/ScriptTest.cpp b/Engine/source/testing/ScriptTest.cpp index c59af9a5e..d13d2b6f2 100644 --- a/Engine/source/testing/ScriptTest.cpp +++ b/Engine/source/testing/ScriptTest.cpp @@ -983,6 +983,114 @@ TEST_F(ScriptTest, InnerObjectTests) ASSERT_EQ(nestedFuncCall.getInt(), 123); } +TEST_F(ScriptTest, SlotOperatorTests) +{ + ConsoleValue testSlot1 = RunScript(R"( + new SimObject(testObjectSlot1); + testObjectSlot1.data[1] = 2; + + function test(%value) + { + testObjectSlot1.data[%value]++; + + return testObjectSlot1.data[%value]; + } + return test(1); + )"); + + ASSERT_EQ(testSlot1.getInt(), 3); + + ConsoleValue testSlot2 = RunScript(R"( + new SimObject(testObjectSlot2); + testObjectSlot2.data[1] = 5; + + function test(%value) + { + testObjectSlot2.data[%value]--; + + return testObjectSlot2.data[%value]; + } + return test(1); + )"); + + ASSERT_EQ(testSlot2.getInt(), 4); + + ConsoleValue testSlot3 = RunScript(R"( + new SimObject(testObjectSlot3); + testObjectSlot3.data[1] = 5; + + function test(%value) + { + testObjectSlot3.data[1] += 1; + + return testObjectSlot3.data[1]; + } + return test(); + )"); + + ASSERT_EQ(testSlot3.getInt(), 6); + + ConsoleValue testSlot4 = RunScript(R"( + new SimObject(testObjectSlot4); + testObjectSlot4.data[1] = 5; + + function test(%value) + { + testObjectSlot4.data[1] -= %value; + + return testObjectSlot4.data[1]; + } + return test(1); + )"); + + ASSERT_EQ(testSlot4.getInt(), 4); + + ConsoleValue testSlot5 = RunScript(R"( + new SimObject(testObjectSlot5); + testObjectSlot5.data[1] = 8; + + function test() + { + testObjectSlot5.data[1] /= 2; + + return testObjectSlot5.data[1]; + } + return test(); + )"); + + ASSERT_EQ(testSlot5.getInt(), 4); + + ConsoleValue testSlot6 = RunScript(R"( + new SimObject(testObjectSlot6); + testObjectSlot6.data[1] = 8; + + function test() + { + testObjectSlot6.data[1] *= 2; + + return testObjectSlot6.data[1]; + } + return test(); + )"); + + ASSERT_EQ(testSlot6.getInt(), 16); + + ConsoleValue testSlot7 = RunScript(R"( + new SimObject(testObjectSlot7); + testObjectSlot7.data[1] = 8; + + function test() + { + testObjectSlot7.data[1] %= 3; + + return testObjectSlot7.data[1]; + } + return test(); + )"); + + ASSERT_EQ(testSlot7.getInt(), 2); +} + TEST_F(ScriptTest, MiscTesting) { ConsoleValue test1 = RunScript(R"(