Skip to content

Commit

Permalink
Merge pull request #32445 from mavasani/Issue31308
Browse files Browse the repository at this point in the history
Fix UseExpressionBodyHelper.GetDiagnosticLocation for indexer declara…
  • Loading branch information
mavasani authored Jan 15, 2019
2 parents 50bb3fa + 5b36e90 commit 9e50109
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.UseExpressionBody;
Expand Down Expand Up @@ -298,6 +299,26 @@ int Goo
}", options: UseBlockBodyIncludingPropertiesAndIndexers);
}

[WorkItem(31308, "https://github.com/dotnet/roslyn/issues/31308")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseExpressionBody)]
public async Task TestUseBlockBody5()
{
var whenOnSingleLineWithNoneEnforcement = new CodeStyleOption<ExpressionBodyPreference>(ExpressionBodyPreference.WhenOnSingleLine, NotificationOption.None);
var options = OptionsSet(
SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedAccessors, whenOnSingleLineWithNoneEnforcement),
SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedProperties, whenOnSingleLineWithNoneEnforcement),
SingleOption(CSharpCodeStyleOptions.PreferExpressionBodiedIndexers, whenOnSingleLineWithNoneEnforcement));

await TestMissingInRegularAndScriptAsync(
@"class C
{
C this[int index]
{
get [|=>|] default;
}
}", new TestParameters(options: options));
}

[WorkItem(20350, "https://github.com/dotnet/roslyn/issues/20350")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseExpressionBody)]
public async Task TestAccessorListFormatting()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,17 @@ protected override bool TryConvertToExpressionBody(
declaration, options, conversionPreference,
out arrowExpression, out semicolonToken);
}

protected override Location GetDiagnosticLocation(IndexerDeclarationSyntax declaration)
{
var body = GetBody(declaration);
if (body != null)
{
return base.GetDiagnosticLocation(declaration);
}

var getAccessor = GetSingleGetAccessor(declaration.AccessorList);
return getAccessor.ExpressionBody.GetLocation();
}
}
}

0 comments on commit 9e50109

Please sign in to comment.