mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
Fix weird ternary operator in torquescript regression
With a test!
This commit is contained in:
parent
35de012ee7
commit
59125c85eb
2 changed files with 22 additions and 1 deletions
|
|
@ -399,7 +399,12 @@ U32 ConditionalExprNode::compile(CodeStream& codeStream, U32 ip, TypeReq type)
|
||||||
|
|
||||||
TypeReq ConditionalExprNode::getPreferredType()
|
TypeReq ConditionalExprNode::getPreferredType()
|
||||||
{
|
{
|
||||||
return trueExpr->getPreferredType();
|
// We can't make it calculate a type based on subsequent expressions as the expression
|
||||||
|
// could be a string, or just numbers. To play it safe, stringify anything that deals with
|
||||||
|
// a conditional, and let the interpreter cast as needed to other types safely.
|
||||||
|
//
|
||||||
|
// See: Regression Test 7 in ScriptTest. It has a string result in the else portion of the ?: ternary.
|
||||||
|
return TypeReqString;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------
|
//------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -1079,6 +1079,22 @@ TEST(Script, MiscRegressions)
|
||||||
)");
|
)");
|
||||||
|
|
||||||
ASSERT_EQ(regression6.getBool(), true);
|
ASSERT_EQ(regression6.getBool(), true);
|
||||||
|
|
||||||
|
ConsoleValue regression7 = RunScript(R"(
|
||||||
|
function Tween::vectorAdd(%v1, %v2)
|
||||||
|
{
|
||||||
|
%temp = "";
|
||||||
|
for (%i = 0; %i < getWordCount(%v1); %i++) {
|
||||||
|
%e = getWord(%v1, %i) + getWord(%v2, %i);
|
||||||
|
%temp = %i == 0 ? %e : %temp SPC %e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return %temp;
|
||||||
|
}
|
||||||
|
return Tween::vectorAdd("1 2 3", "4 5 6");
|
||||||
|
)");
|
||||||
|
|
||||||
|
ASSERT_STREQ(regression7.getString(), "5 7 9");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue