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

Implement interface produces incorrect code for manual use of DefaultParameterValue and Optional #54326

Closed
sharwell opened this issue Jun 23, 2021 · 1 comment
Labels
Area-IDE Bug IDE-CodeStyle Built-in analyzers, fixes, and refactorings
Milestone

Comments

@sharwell
Copy link
Member

sharwell commented Jun 23, 2021

Two Implement Interface tests reveal broken code when DefaultParameterValue and Optional are used:

[WorkItem(545793, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545793")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)]
public async Task TestMultiDimArray()
{
await TestWithAllCodeStyleOptionsOffAsync(
@"using System.Runtime.InteropServices;
interface I
{
void Goo([Optional][DefaultParameterValue(1)] int x, int[,] y);
}
class C : {|CS0535:I|}
{
}",
@"using System.Runtime.InteropServices;
interface I
{
void Goo([Optional][DefaultParameterValue(1)] int x, int[,] y);
}
class C : I
{
public void Goo([{|CS1745:DefaultParameterValue|}(1), {|CS1745:Optional|}] int x = {|CS8017:1|}, int[,] y = null)
{
throw new System.NotImplementedException();
}
}");
}
[WorkItem(545794, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545794")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)]
public async Task TestParametersAfterOptionalParameter()
{
await TestWithAllCodeStyleOptionsOffAsync(
@"using System.Runtime.InteropServices;
interface I
{
void Goo([Optional, DefaultParameterValue(1)] int x, int[] y, int[] z);
}
class C : {|CS0535:I|}
{
}",
@"using System.Runtime.InteropServices;
interface I
{
void Goo([Optional, DefaultParameterValue(1)] int x, int[] y, int[] z);
}
class C : I
{
public void Goo([{|CS1745:DefaultParameterValue|}(1), {|CS1745:Optional|}] int x = {|CS8017:1|}, int[] y = null, int[] z = null)
{
throw new System.NotImplementedException();
}
}");
}

🐛 this code generation is not correct. I'm guess the result we want is:

    public void Goo(int x = 1, int[,] y = null)

Originally posted by @sharwell in #54310 (comment)

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Infrastructure untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 23, 2021
@sharwell sharwell added Area-IDE Bug IDE-CodeStyle Built-in analyzers, fixes, and refactorings and removed Area-Infrastructure labels Jun 23, 2021
@jinujoseph jinujoseph removed the untriaged Issues and PRs which have not yet been triaged by a lead label Jun 25, 2021
@jinujoseph jinujoseph added this to the 17.0 milestone Jun 25, 2021
@jinujoseph jinujoseph modified the milestones: 17.0, Backlog Jul 27, 2021
@CyrusNajmabadi
Copy link
Member

Closing out as not a priority for us. Manual application of these attributes is a not an important scenario.

@CyrusNajmabadi CyrusNajmabadi closed this as not planned Won't fix, can't repro, duplicate, stale Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug IDE-CodeStyle Built-in analyzers, fixes, and refactorings
Projects
None yet
Development

No branches or pull requests

3 participants