Skip to content

Commit 3a27cbe

Browse files
Fix #3617: Order of XML comments in types with primary constructors
1 parent c0a9afc commit 3a27cbe

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

ICSharpCode.Decompiler/CSharp/Syntax/GeneralScope/TypeDeclaration.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,30 @@ public CSharpTokenNode RChevronToken {
100100
get { return GetChildByRole(Roles.RChevron); }
101101
}
102102

103-
104-
105103
public CSharpTokenNode ColonToken {
106104
get {
107105
return GetChildByRole(Roles.Colon);
108106
}
109107
}
110108

111-
public AstNodeCollection<AstType> BaseTypes {
112-
get { return GetChildrenByRole(Roles.BaseType); }
113-
}
114-
115109
public bool HasPrimaryConstructor { get; set; }
116110

111+
public CSharpTokenNode LParToken {
112+
get { return GetChildByRole(Roles.LPar); }
113+
}
114+
117115
public AstNodeCollection<ParameterDeclaration> PrimaryConstructorParameters {
118116
get { return GetChildrenByRole(Roles.Parameter); }
119117
}
120118

119+
public CSharpTokenNode RParToken {
120+
get { return GetChildByRole(Roles.RPar); }
121+
}
122+
123+
public AstNodeCollection<AstType> BaseTypes {
124+
get { return GetChildrenByRole(Roles.BaseType); }
125+
}
126+
121127
public AstNodeCollection<Constraint> Constraints {
122128
get { return GetChildrenByRole(Roles.Constraint); }
123129
}

ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,19 @@ public void RemoveImplicitConstructor()
598598
|| !PrimaryConstructorDecl.Initializer.IsNull
599599
|| TypeDefinition.Kind == TypeKind.Struct;
600600

601-
PrimaryConstructorDecl.Parameters.MoveTo(this.TypeDeclaration.PrimaryConstructorParameters);
601+
// HACK: because our current AST model doesn't allow specifying an explicit order of roles,
602+
// we have to explicitly insert the primary constructor parameters,
603+
// MoveTo would just append the parameters to the list of children
604+
if (PrimaryConstructorDecl.Parameters.Count > 0)
605+
{
606+
var insertionPoint = (AstNode?)this.TypeDeclaration.TypeParameters.LastOrDefault() ?? this.TypeDeclaration.NameToken;
607+
foreach (var param in PrimaryConstructorDecl.Parameters)
608+
{
609+
param.Remove();
610+
this.TypeDeclaration.InsertChildAfter(insertionPoint, param, Roles.Parameter);
611+
insertionPoint = param;
612+
}
613+
}
602614

603615
Debug.Assert(PrimaryConstructorParameterToBackingStoreMap != null);
604616

0 commit comments

Comments
 (0)