Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,8 @@ public static void RestorePreviousParameterNames(
string? preservedName = null;

var inputParameter = parameter.InputParameter;
if (inputParameter is not null)
if (inputParameter is not null && string.Equals(parameter.Name, inputParameter.Name, StringComparison.Ordinal))
{
if (!string.Equals(parameter.Name, inputParameter.Name, StringComparison.Ordinal))
{
continue;
}

var originalName = inputParameter.OriginalName;
if (!string.IsNullOrEmpty(originalName))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// <auto-generated/>

#nullable disable

namespace Test
{
public partial class TestClient
{
public string Foo(string defaultName)
{
this.Validate(defaultName);
return defaultName;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Test
{
public class TestClient
{
public string Foo(string defaultName) { return null; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,36 @@ public async Task BuildMethodsForBackCompatibilityRestoresRenamedParameterBySign
Assert.AreEqual(Helpers.GetExpectedFromFile(), actual);
}

// Validates that synthesized parameters retain the positional fallback even when their public name
// differs from the InputParameter they originated from.
[Test]
public async Task BuildMethodsForBackCompatibilityRestoresSynthesizedParameterNameBySignatureMatch()
{
await MockHelpers.LoadMockGeneratorAsync(lastContractCompilation: async () => await Helpers.GetCompilationFromDirectoryAsync());

var inputParameter = InputFactory.QueryParameter("wireName", InputPrimitiveType.String, isRequired: true);
var parameter = new ParameterProvider(
"default",
$"",
new CSharpType(typeof(string)),
inputParameter: inputParameter);
var fooMethod = new MethodProvider(
new MethodSignature("Foo", $"", MethodSignatureModifiers.Public, new CSharpType(typeof(string)), $"", [parameter]),
new MethodBodyStatement[]
{
Snippet.This.Invoke("Validate", parameter).Terminate(),
Snippet.Return(parameter),
},
new TestTypeProvider());

var typeProvider = new TestTypeProvider(name: "TestClient", methods: [fooMethod]);

typeProvider.ProcessTypeForBackCompatibility();

var actual = new TypeProviderWriter(typeProvider).Write().Content;
Assert.AreEqual(Helpers.GetExpectedFromFile(), actual);
}

// When the restored name is used both as an argument (AsArgument -> _asArgument) and
// as a variable (-> _asVariable), materializing both cached expressions before the rename, the
// rename must keep them sharing one declaration. Otherwise the writer renames the two
Expand Down
Loading