Merge pull request #12837 from pchote/negative-int-negation

Make ConditionExpression ! return false for negative numbers.
This commit is contained in:
reaperrr
2017-02-25 12:21:34 +01:00
committed by GitHub
2 changed files with 3 additions and 11 deletions

View File

@@ -641,12 +641,7 @@ namespace OpenRA.Support
static Expression AsBool(Expression expression)
{
return Expressions.Expression.GreaterThan(expression, Zero);
}
static Expression AsNegBool(Expression expression)
{
return Expressions.Expression.LessThanOrEqual(expression, Zero);
return Expressions.Expression.NotEqual(expression, Zero);
}
static Expression IfThenElse(Expression test, Expression ifTrue, Expression ifFalse)
@@ -757,10 +752,7 @@ namespace OpenRA.Support
case TokenType.Not:
{
if (ast.PeekType() == ExpressionType.Bool)
ast.Push(Expressions.Expression.Not(ast.Pop(ExpressionType.Bool)));
else
ast.Push(AsNegBool(ast.Pop(ExpressionType.Int)));
ast.Push(Expressions.Expression.Not(ast.Pop(ExpressionType.Bool)));
continue;
}

View File

@@ -163,7 +163,7 @@ namespace OpenRA.Test
AssertValue("!1", 0);
AssertValue("!5", 0);
AssertValue("!!5", 1);
AssertValue("!-5", 1);
AssertValue("!-5", 0);
}
[TestCase(TestName = "Relation operations")]