Skip to content
Permalink
Browse files

Fix compound assignments with type `bool`.

This required removing the "Replace bit.and with logic.and" transform, as it interfered with the compound assignment transform.
  • Loading branch information
dgrunwald committed Nov 30, 2019
1 parent 9e460f3 commit 93806b46fa8befaae5768e01e838e703bc9a96ce
@@ -60,6 +60,11 @@ public class MutableClass
get;
set;
}

public bool BoolProperty {
get;
set;
}

public uint this[string name] {
get {
@@ -802,6 +807,23 @@ public int DoubleInstancePropertyByteAndReturn()
return M().ByteProperty *= 2;
}

public void BitManipBoolProperty(bool b)
{
M().BoolProperty |= b;
M().BoolProperty &= b;
M().BoolProperty ^= b;
}

public bool BitOrBoolPropertyAndReturn(bool b)
{
return M().BoolProperty |= b;
}

public bool BitAndBoolPropertyAndReturn(bool b)
{
return M().BoolProperty &= b;
}

public int PreIncrementStaticField()
{
return ++StaticField;
@@ -679,11 +679,6 @@ protected internal override void VisitBinaryNumericInstruction(BinaryNumericInst
{
if (new NullableLiftingTransform(context).Run(inst)) {
// e.g. "(a.GetValueOrDefault() == b.GetValueOrDefault()) & (a.HasValue & b.HasValue)"
} else if (SemanticHelper.IsPure(inst.Right.Flags)) {
context.Step("Replace bit.and with logic.and", inst);
var expr = IfInstruction.LogicAnd(inst.Left, inst.Right);
inst.ReplaceWith(expr);
expr.AcceptVisitor(this);
}
}
break;
@@ -459,6 +459,16 @@ static internal bool IsImplicitTruncation(ILInstruction value, IType type, IComp
return conv.TargetType != type.ToPrimitiveType();
} else if (value is Comp) {
return false; // comp returns 0 or 1, which always fits
} else if (value is BinaryNumericInstruction bni) {
switch (bni.Operator) {
case BinaryNumericOperator.BitAnd:
case BinaryNumericOperator.BitOr:
case BinaryNumericOperator.BitXor:
// If both input values fit into the type without truncation,
// the result of a binary operator will also fit.
return IsImplicitTruncation(bni.Left, type, compilation, allowNullableValue)
|| IsImplicitTruncation(bni.Right, type, compilation, allowNullableValue);
}
} else if (value is IfInstruction ifInst) {
return IsImplicitTruncation(ifInst.TrueInst, type, compilation, allowNullableValue)
|| IsImplicitTruncation(ifInst.FalseInst, type, compilation, allowNullableValue);

0 comments on commit 93806b4

Please sign in to comment.
You can’t perform that action at this time.