Browse Source

Fix #3820: decompile dynamic ~ as ~x instead of an unsupported-opcode error

VisitDynamicUnaryOperatorInstruction handled every dynamic unary operator
except ExpressionType.OnesComplement, so ~x on a dynamic operand fell through
to the unsupported-opcode error expression and produced uncompilable output
(an incomplete cast that fails to parse). Map it to the bitwise-complement
operator, like the sibling unary cases.

Assisted-by: Copilot:claude-opus-4.8:GitHub Copilot CLI
pull/3834/head
Sebastien Lebreton 2 weeks ago committed by Siegfried Pammer
parent
commit
44cb31abae
  1. 1
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

1
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs

@ -394,6 +394,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -394,6 +394,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
//++a;
DynamicTests.Casts(-a);
DynamicTests.Casts(+a);
DynamicTests.Casts(~a);
}
private static void Loops(dynamic list)

2
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -4540,6 +4540,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -4540,6 +4540,8 @@ namespace ICSharpCode.Decompiler.CSharp
return CreateUnaryOperator(UnaryOperatorType.Minus, isChecked: true);
case ExpressionType.UnaryPlus:
return CreateUnaryOperator(UnaryOperatorType.Plus, isChecked: inst.BinderFlags.HasFlag(CSharpBinderFlags.CheckedContext));
case ExpressionType.OnesComplement:
return CreateUnaryOperator(UnaryOperatorType.BitNot);
case ExpressionType.IsTrue:
var operand = TranslateDynamicArgument(inst.Operand, inst.OperandArgumentInfo);
Expression expr;

Loading…
Cancel
Save