diff options
-rw-r--r-- | GenPy.cs | 9 | ||||
-rw-r--r-- | test/OpBoolLogic.ci | 2 | ||||
-rw-r--r-- | test/OpNot.ci | 2 |
3 files changed, 8 insertions, 5 deletions
@@ -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) |