提交 e5248077 编写于 作者: S Sam Harwell

Add Extract Method tests for by-ref pass through

Closes #19136
上级 ece8f8d8
......@@ -10120,6 +10120,114 @@ private static void NewMethod()
await TestExtractMethodAsync(code, expected);
}
[Fact, Trait(Traits.Feature, Traits.Features.ExtractMethod)]
[WorkItem(19958, "https://github.com/dotnet/roslyn/issues/19958")]
public async Task TestExtractMethodRefPassThrough()
{
var code =
@"using System;
namespace ClassLibrary9
{
internal class ClassExtensions
{
public static int OtherMethod(ref int x) => x;
public static void Method(ref int x)
=> Console.WriteLine(OtherMethod(ref [|x|]));
}
}";
var expected =
@"using System;
namespace ClassLibrary9
{
internal class ClassExtensions
{
public static int OtherMethod(ref int x) => x;
public static void Method(ref int x)
=> Console.WriteLine(OtherMethod(ref $x$));
public static ref int NewMethod(ref int x)
{
return ref x;
}
}
}";
await TestExtractMethodAsync(code, expected, temporaryFailing: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.ExtractMethod)]
[WorkItem(19958, "https://github.com/dotnet/roslyn/issues/19958")]
public async Task TestExtractMethodRefPassThroughDuplicateVariable()
{
var code =
@"using System;
namespace ClassLibrary9
{
internal interface IClass
{
bool InterfaceMethod(ref Guid x, out IOtherClass y);
}
internal interface IOtherClass
{
bool OtherInterfaceMethod();
}
internal static class ClassExtensions
{
public static void Method(this IClass instance, Guid guid)
{
var r = instance.InterfaceMethod(ref [|guid|], out IOtherClass guid);
if (!r)
return;
r = guid.OtherInterfaceMethod();
if (r)
throw null;
}
}
}";
var expected =
@"using System;
namespace ClassLibrary9
{
internal interface IClass
{
bool InterfaceMethod(ref Guid x, out IOtherClass y);
}
internal interface IOtherClass
{
bool OtherInterfaceMethod();
}
internal static class ClassExtensions
{
public static void Method(this IClass instance, Guid guid)
{
var r = instance.InterfaceMethod(ref NewMethod(ref guid), out IOtherClass guid);
if (!r)
return;
r = guid.OtherInterfaceMethod();
if (r)
throw null;
}
public static ref Guid NewMethod(ref Guid guid)
{
return ref guid;
}
}
}";
await TestExtractMethodAsync(code, expected, temporaryFailing: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.ExtractMethod)]
public async Task ExtractMethod_Argument1()
{
......
......@@ -73,6 +73,13 @@ static ExtractMethodMatrix()
{
key = new Key(dataFlowIn, /*dataFlowOut*/ true, alwaysAssigned, variableDeclared, readInside, writtenInside, readOutside, writtenOutside);
}
// interesting case in invalid code (bug #19136)
// variable is passed by reference, and another argument is an out variable with the same name
if (dataFlowIn && variableDeclared)
{
key = new Key(/*dataFlowIn:*/ false, dataFlowOut, alwaysAssigned, variableDeclared, readInside, writtenInside, readOutside, writtenOutside);
}
}
Contract.ThrowIfFalse(s_matrix.ContainsKey(key));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册