summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Fusik <fox@scene.pl>2022-01-22 11:03:30 +0100
committerPiotr Fusik <fox@scene.pl>2022-01-22 11:03:30 +0100
commit82cce42ba5ce8f5d3e3bd727e3e2dc10d98f1d4c (patch)
treeb49f3d6fd9c42ce5bf4c9f6ce7e3b228d3e5e942
parent8c079007c935c793c32db9c2f0480e16c9e96fdb (diff)
[py] Fix "not" operator precedence.
-rw-r--r--GenPy.cs9
-rw-r--r--test/OpBoolLogic.ci2
-rw-r--r--test/OpNot.ci2
3 files changed, 8 insertions, 5 deletions
diff --git a/GenPy.cs b/GenPy.cs
index 6343074..921337f 100644
--- a/GenPy.cs
+++ b/GenPy.cs
@@ -246,12 +246,15 @@ public class GenPy : GenPySwift
public override CiExpr Visit(CiPrefixExpr expr, CiPriority parent)
{
if (expr.Op == CiToken.ExclamationMark) {
+ if (parent > CiPriority.CondAnd)
+ Write('(');
Write("not ");
- expr.Inner.Accept(this, CiPriority.Primary);
+ expr.Inner.Accept(this, CiPriority.Or);
+ if (parent > CiPriority.CondAnd)
+ Write(')');
return expr;
}
- else
- return base.Visit(expr, parent);
+ return base.Visit(expr, parent);
}
static bool IsPtr(CiExpr expr) => expr.Type is CiClassPtrType || expr.Type is CiArrayPtrType;
diff --git a/test/OpBoolLogic.ci b/test/OpBoolLogic.ci
index 432bea6..8ae7e7b 100644
--- a/test/OpBoolLogic.ci
+++ b/test/OpBoolLogic.ci
@@ -4,7 +4,7 @@ public static class Test
{
bool t = true;
bool f = false;
- return (t & !f) //FAIL: python swift ts TODO
+ return (t & !f) //FAIL: swift ts TODO
&& (t | f)
&& (t ^ f);
}
diff --git a/test/OpNot.ci b/test/OpNot.ci
index af8a39d..206f29c 100644
--- a/test/OpNot.ci
+++ b/test/OpNot.ci
@@ -7,7 +7,7 @@ public static class Test
bool t = true;
return !a
&& !(a && a)
- && !(a && !a) //FAIL: python TODO
+ && !(a && !a)
&& !(a & a) //FAIL: swift ts TODO
&& !(a & !a)
&& !(!t & a)