Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix syntax normalizer to add space around before colon in constructor initializer #53326

Merged
merged 3 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Compilers/CSharp/Portable/Syntax/SyntaxNormalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
Expand Down Expand Up @@ -604,7 +602,8 @@ private static bool NeedsSeparator(SyntaxToken token, SyntaxToken next)
if (next.IsKind(SyntaxKind.ColonToken))
{
if (next.Parent.IsKind(SyntaxKind.BaseList) ||
next.Parent.IsKind(SyntaxKind.TypeParameterConstraintClause))
next.Parent.IsKind(SyntaxKind.TypeParameterConstraintClause) ||
next.Parent is ConstructorInitializerSyntax)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,12 @@ public void TestSpacingOnInvocationLikeKeywords()
// no space between this and (
TestNormalizeDeclaration(
"class C { C() : this () { } }",
"class C\r\n{\r\n C(): this()\r\n {\r\n }\r\n}");
"class C\r\n{\r\n C() : this()\r\n {\r\n }\r\n}");

// no space between base and (
TestNormalizeDeclaration(
"class C { C() : base () { } }",
"class C\r\n{\r\n C(): base()\r\n {\r\n }\r\n}");
"class C\r\n{\r\n C() : base()\r\n {\r\n }\r\n}");

// no space between checked and (
TestNormalizeExpression("checked (a)", "checked(a)");
Expand Down Expand Up @@ -920,6 +920,35 @@ public void TestNormalizeFunctionPointerWithUnmanagedCallingConventionAndSpecifi
TestNormalizeDeclaration(content, expected);
}

[Fact]
[WorkItem(53254, "https://github.com/dotnet/roslyn/issues/53254")]
public void TestNormalizeColonInConstructorInitializer()
{
var content =
@"class Base
{
}

class Derived : Base
{
public Derived():base(){}
}";

var expected =
@"class Base
{
}

class Derived : Base
{
public Derived() : base()
{
}
}";

TestNormalizeDeclaration(content, expected);
}

[Fact]
[WorkItem(49732, "https://github.com/dotnet/roslyn/issues/49732")]
public void TestNormalizeXmlInDocComment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ public void TestConstructorDeclaration()
Generator.ConstructorDeclaration("c",
parameters: new[] { Generator.ParameterDeclaration("p", Generator.IdentifierName("t")) },
baseConstructorArguments: new[] { Generator.IdentifierName("p") }),
"c(t p): base(p)\r\n{\r\n}");
"c(t p) : base(p)\r\n{\r\n}");
}

[Fact]
Expand Down