Skip to content

Commit

Permalink
Fix NRE in DoDecompile(FieldDefinition) on internal value__ enum fields
Browse files Browse the repository at this point in the history
  • Loading branch information
siegfriedpammer committed Dec 16, 2017
1 parent 5184a9b commit 889b147
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,15 +826,15 @@ EntityDeclaration DoDecompile(FieldDefinition fieldDefinition, IField field, ITy
{
Debug.Assert(decompilationContext.CurrentMember == field);
var typeSystemAstBuilder = CreateAstBuilder(decompilationContext);
if (decompilationContext.CurrentTypeDefinition.Kind == TypeKind.Enum) {
if (decompilationContext.CurrentTypeDefinition.Kind == TypeKind.Enum && field.ConstantValue != null) {
var index = decompilationContext.CurrentTypeDefinition.Members.IndexOf(field);
long previousValue = -1;
if (index > 0) {
var previousMember = (IField)decompilationContext.CurrentTypeDefinition.Members[index - 1];
previousValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, previousMember.ConstantValue, false);
}
long initValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, field.ConstantValue, false);
var enumDec = new EnumMemberDeclaration { Name = field.Name };
long initValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, field.ConstantValue, false);
if (decompilationContext.CurrentTypeDefinition.Attributes.Any(a => a.AttributeType.FullName == "System.FlagsAttribute")) {
enumDec.Initializer = typeSystemAstBuilder.ConvertConstantValue(decompilationContext.CurrentTypeDefinition.EnumUnderlyingType, field.ConstantValue);
if (enumDec.Initializer is PrimitiveExpression primitive && initValue > 9)
Expand Down

0 comments on commit 889b147

Please sign in to comment.