Browse Source

Fix #2396: Extend the #1903 workaround to unconstrained generic types.

The logic in the `FixLoneIsInst` transform already handled this correctly, it's just the check in the `isinst` translation that handled the `IsReferenceType == null` case incorrectly.
pull/2408/head
Daniel Grunwald 4 years ago
parent
commit
d917a3706b
  1. 3
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

3
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -373,10 +373,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -373,10 +373,11 @@ namespace ICSharpCode.Decompiler.CSharp
protected internal override TranslatedExpression VisitIsInst(IsInst inst, TranslationContext context)
{
var arg = Translate(inst.Argument);
if (inst.Type.IsReferenceType == false)
if (inst.Type.IsReferenceType != true)
{
// isinst with a value type results in an expression of "boxed value type",
// which is not supported in C#.
// It's also not supported for unconstrained generic types.
// Note that several other instructions special-case isinst arguments:
// unbox.any T(isinst T(expr)) ==> "expr as T" for nullable value types and class-constrained generic types
// comp(isinst T(expr) != null) ==> "expr is T"

Loading…
Cancel
Save