Browse Source

Merge pull request #3021 from andrewcrawley/record-unknown-base

Fix decompilation of record with missing base type
pull/3024/head
Daniel Grunwald 2 years ago committed by GitHub
parent
commit
dcd1a0775a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs

8
ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs

@ -53,8 +53,8 @@ namespace ICSharpCode.Decompiler.CSharp
this.settings = settings; this.settings = settings;
this.cancellationToken = cancellationToken; this.cancellationToken = cancellationToken;
this.baseClass = recordTypeDef.DirectBaseTypes.FirstOrDefault(b => b.Kind == TypeKind.Class); this.baseClass = recordTypeDef.DirectBaseTypes.FirstOrDefault(b => b.Kind == TypeKind.Class);
this.isStruct = baseClass.IsKnownType(KnownTypeCode.ValueType); this.isStruct = baseClass?.IsKnownType(KnownTypeCode.ValueType) ?? false;
this.isInheritedRecord = !isStruct && !baseClass.IsKnownType(KnownTypeCode.Object); this.isInheritedRecord = !isStruct && !(baseClass?.IsKnownType(KnownTypeCode.Object) ?? false);
this.isSealed = recordTypeDef.IsSealed; this.isSealed = recordTypeDef.IsSealed;
DetectAutomaticProperties(); DetectAutomaticProperties();
this.orderedMembers = DetectMemberOrder(recordTypeDef, backingFieldToAutoProperty); this.orderedMembers = DetectMemberOrder(recordTypeDef, backingFieldToAutoProperty);
@ -292,7 +292,7 @@ namespace ICSharpCode.Decompiler.CSharp
// virtual bool Equals(R? other): generated unless user-declared // virtual bool Equals(R? other): generated unless user-declared
return IsGeneratedEquals(method); return IsGeneratedEquals(method);
} }
else if (isInheritedRecord && NormalizeTypeVisitor.TypeErasure.EquivalentTypes(paramType, baseClass) && method.IsOverride) else if (isInheritedRecord && baseClass != null && NormalizeTypeVisitor.TypeErasure.EquivalentTypes(paramType, baseClass) && method.IsOverride)
{ {
// override bool Equals(BaseClass? obj): always generated // override bool Equals(BaseClass? obj): always generated
return true; return true;
@ -772,7 +772,7 @@ namespace ICSharpCode.Decompiler.CSharp
return false; return false;
if (!(conditions[pos] is Call { Method: { Name: "Equals" } } call)) if (!(conditions[pos] is Call { Method: { Name: "Equals" } } call))
return false; return false;
if (!NormalizeTypeVisitor.TypeErasure.EquivalentTypes(call.Method.DeclaringType, baseClass)) if (baseClass != null && !NormalizeTypeVisitor.TypeErasure.EquivalentTypes(call.Method.DeclaringType, baseClass))
return false; return false;
if (call.Arguments.Count != 2) if (call.Arguments.Count != 2)
return false; return false;

Loading…
Cancel
Save