Skip to content

Commit

Permalink
Fix #3189: Support primitive types in Expression.Constant(object) pat…
Browse files Browse the repository at this point in the history
…tern.
  • Loading branch information
siegfriedpammer committed Jun 6, 2024
1 parent c269b99 commit 401cb77
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ICSharpCode.Decompiler/IL/Transforms/TransformExpressionTrees.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;

using ICSharpCode.Decompiler.CSharp.Resolver;
using ICSharpCode.Decompiler.Semantics;
Expand Down Expand Up @@ -1423,7 +1422,15 @@ bool MatchConstantCall(ILInstruction inst, out ILInstruction value, out IType ty
value = call.Arguments[0];
if (call.Arguments.Count == 2)
return MatchGetTypeFromHandle(call.Arguments[1], out type);
type = value.InferType(context.TypeSystem);
type = value switch {
LdNull => SpecialType.NullType,
LdStr => context.TypeSystem.FindType(KnownTypeCode.String),
LdcF4 => context.TypeSystem.FindType(KnownTypeCode.Single),
LdcF8 => context.TypeSystem.FindType(KnownTypeCode.Double),
LdcI4 => context.TypeSystem.FindType(KnownTypeCode.Int32),
LdcI8 => context.TypeSystem.FindType(KnownTypeCode.Int64),
_ => value.InferType(context.TypeSystem),
};
return true;
}
return false;
Expand Down

0 comments on commit 401cb77

Please sign in to comment.