Skip to content

Commit

Permalink
Suppressing inline temp refactoring on byref locals.
Browse files Browse the repository at this point in the history
The feature needs to be properly implemented taking into account that variable is byref.
For now disabling this refactoring if variable happen to be byref to avoid crash as described in dotnet#8416
  • Loading branch information
VSadov committed Feb 19, 2016
1 parent 6d02c04 commit c734932
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
using Microsoft.CodeAnalysis.CSharp.CodeRefactorings.InlineTemporary;
using Roslyn.Test.Utilities;
using Xunit;
using System.Collections.Generic;

namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings.InlineTemporary
{
public class InlineTemporaryTests : AbstractCSharpCodeActionTest
{
private static readonly Dictionary<string, string> s_experimentalFeatures = new Dictionary<string, string> { { "localFunctions", "true" }, { "refLocalsAndReturns", "true" } };
public static readonly CSharpParseOptions ExperimentalParseOptions =
new CSharpParseOptions(kind: SourceCodeKind.Regular, documentationMode: DocumentationMode.None, languageVersion: LanguageVersion.CSharp6).WithFeatures(s_experimentalFeatures);

protected override object CreateCodeRefactoringProvider(Workspace workspace)
{
return new InlineTemporaryCodeRefactoringProvider();
Expand Down Expand Up @@ -62,6 +67,23 @@ public async Task NotOnField()
await TestMissingAsync(@"class C { int [||]x = 42; void M() { System.Console.WriteLine(x); } }");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineTemporary)]
public async Task WithRefInitializer1()
{
await TestMissingAsync(@"
class C
{
ref int M()
{
int[] arr = new[] { 1, 2, 3 };
ref int [||]x = ref arr[2];
return ref x;
}
}",
// TODO: propagating features to the project is currently NYI
parseOptions: ExperimentalParseOptions);
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineTemporary)]
public async Task SingleStatement()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
return;
}

if (variableDeclarator.Initializer.RefKeyword.Kind() != SyntaxKind.None)
{
// TODO: inlining byref temps is NYI
return;
}

if (localDeclarationStatement.ContainsDiagnostics)
{
return;
Expand Down

0 comments on commit c734932

Please sign in to comment.