summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Fusik <fox@scene.pl>2022-01-22 11:01:16 +0100
committerPiotr Fusik <fox@scene.pl>2022-01-22 11:01:16 +0100
commit8c079007c935c793c32db9c2f0480e16c9e96fdb (patch)
treed2deb2c3f5acb4a41f6cb0701fbc30cdd6d9d47e
parent66d1fa77bf89b0fcab7c46a28e139cc38d2c3e6b (diff)
[bool] Eager operators.
-rw-r--r--CiResolver.cs8
-rw-r--r--test/OpBoolLogic.ci11
-rw-r--r--test/OpNot.ci12
3 files changed, 26 insertions, 5 deletions
diff --git a/CiResolver.cs b/CiResolver.cs
index 9701a01..8a2cd0e 100644
--- a/CiResolver.cs
+++ b/CiResolver.cs
@@ -248,9 +248,9 @@ public class CiResolver : CiVisitor
delegate CiRangeType UnsignedOp(CiRangeType left, CiRangeType right);
- bool IsEnumFlags(CiExpr left, CiExpr right)
+ bool IsEnumOp(CiExpr left, CiExpr right)
{
- if (left.Type is CiEnumFlags) {
+ if (left.Type is CiEnumFlags || left.Type == CiSystem.BoolType) {
Coerce(right, left.Type);
return true;
}
@@ -279,7 +279,7 @@ public class CiResolver : CiVisitor
}
return range;
}
- if (IsEnumFlags(left, right))
+ if (IsEnumOp(left, right))
return left.Type;
return GetIntegerType(left, right);
}
@@ -848,7 +848,7 @@ public class CiResolver : CiVisitor
case CiToken.OrAssign:
case CiToken.XorAssign:
CheckLValue(left);
- if (!IsEnumFlags(left, right)) {
+ if (!IsEnumOp(left, right)) {
Coerce(left, CiSystem.IntType);
Coerce(right, CiSystem.IntType);
}
diff --git a/test/OpBoolLogic.ci b/test/OpBoolLogic.ci
new file mode 100644
index 0000000..432bea6
--- /dev/null
+++ b/test/OpBoolLogic.ci
@@ -0,0 +1,11 @@
+public static class Test
+{
+ public static bool Run()
+ {
+ bool t = true;
+ bool f = false;
+ return (t & !f) //FAIL: python swift ts TODO
+ && (t | f)
+ && (t ^ f);
+ }
+}
diff --git a/test/OpNot.ci b/test/OpNot.ci
index 40a4294..af8a39d 100644
--- a/test/OpNot.ci
+++ b/test/OpNot.ci
@@ -2,7 +2,17 @@ public static class Test
{
public static bool Run()
{
+ int i = 5;
bool a = false;
- return !a;
+ bool t = true;
+ return !a
+ && !(a && a)
+ && !(a && !a) //FAIL: python TODO
+ && !(a & a) //FAIL: swift ts TODO
+ && !(a & !a)
+ && !(!t & a)
+ && (!a | !a)
+ && !(i == 0)
+ && !(i != 5);
}
}