Skip to content

Commit 554ec92

Browse files
committed
Fix the issue where parameters in the base class constructor call are not passed correctly for inherited classes declared using the primary constructor form (e.g., the DeserializationException type in RestSharp), and also fix the subsequent issue where an extra parenthesis '()' is output if the base class is an interface (e.g., the XmlRestSerializer type in RestSharp).
1 parent 828fb52 commit 554ec92

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,21 @@ public override void VisitConstructorDeclaration(ConstructorDeclaration construc
125125
if (context.DecompileRun.RecordDecompilers.TryGetValue(currentCtor.DeclaringTypeDefinition, out var record)
126126
&& currentCtor.Equals(record.PrimaryConstructor))
127127
{
128-
if (record.IsInheritedRecord &&
129-
ci?.ConstructorInitializerType == ConstructorInitializerType.Base &&
128+
if (ci?.ConstructorInitializerType == ConstructorInitializerType.Base &&
130129
constructorDeclaration.Parent is TypeDeclaration { BaseTypes: { Count: >= 1 } } typeDecl)
131130
{
132-
var baseType = typeDecl.BaseTypes.First();
133-
var newBaseType = new InvocationAstType();
134-
baseType.ReplaceWith(newBaseType);
135-
newBaseType.BaseType = baseType;
136-
ci.Arguments.MoveTo(newBaseType.Arguments);
131+
// Only perform this transformation if the declaring type actually has a non-object class base.
132+
// This prevents converting implemented interfaces into an invocation type (which caused the
133+
// spurious trailing '()' in the decompiled output).
134+
var baseClassType = currentCtor.DeclaringTypeDefinition.DirectBaseTypes.FirstOrDefault(b => b.Kind == TypeKind.Class);
135+
if (baseClassType != null && !baseClassType.IsKnownType(KnownTypeCode.Object))
136+
{
137+
var baseType = typeDecl.BaseTypes.First();
138+
var newBaseType = new InvocationAstType();
139+
baseType.ReplaceWith(newBaseType);
140+
newBaseType.BaseType = baseType;
141+
ci.Arguments.MoveTo(newBaseType.Arguments);
142+
}
137143
}
138144
if (constructorDeclaration.Parent is TypeDeclaration { PrimaryConstructorParameters: var parameters })
139145
{

0 commit comments

Comments
 (0)