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 @@ -1430,6 +1430,38 @@ private void M(int [|x|])
");
}

[WorkItem(57814, "https://github.com/dotnet/roslyn/issues/57814")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnusedParameters)]
public async Task UnusedParameterInPartialMethodImplementation_NoDiagnostic()
{
await TestDiagnosticMissingAsync(
@"
public partial class C
{
public partial void M(int x);
}

public partial class C
{
public partial void M(int [|x|])
{
}
}
");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnusedParameters)]
public async Task ParameterInPartialMethodDefinition_NoDiagnostic()
{
await TestDiagnosticMissingAsync(
@"
public partial class C
{
public partial void M(int [|x|]);
}
");
}

[Fact, WorkItem(36817, "https://github.com/dotnet/roslyn/issues/36817")]
public async Task ParameterWithoutName_NoDiagnostic()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void M()
}

[Fact]
public async Task Initialization_ConstantValue_RemoveUnsuedParametersSuppressed()
public async Task Initialization_ConstantValue_RemoveUnusedParametersSuppressed()
{
var source =
@"class C
Expand Down Expand Up @@ -214,7 +214,7 @@ int M()
}

[Fact]
public async Task Initialization_ConstantValue_RemoveUnsuedParametersNotApplicable()
public async Task Initialization_ConstantValue_RemoveUnusedParametersNotApplicable()
{
var source =
@"class C
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ parameter.ContainingSymbol is not IMethodSymbol method ||
method.IsVirtual ||
method.IsOverride ||
method.PartialImplementationPart != null ||
method.PartialDefinitionPart != null ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, but I feel the check is too strong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that

  • a partial method definition might be generated by some tool, with a parameter list as part of its signature
  • the corresponding implementation must have the same signature

I believe it's pointless to run the IDE0060 rule on the implementation (i.e. when method.PartialDefinitionPart != null ).

After all, if any of the parameters are unused by the implementation, what can the developer do? They probably have no control over the autogenerated definition and the implementation's signature must match the definition's...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should specifically check for generated code. This check can probably be easier when #63447 is merged

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about this upcoming IsGeneratedCode flag. You're right, waiting for it sounds like a good idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if IsGeneratedCode check helps here. The callback would only be made for non-generated code for IDE0060 analyzer, and you can't check whether or not the other partial symbol is generated or not from this callback.

!method.ExplicitOrImplicitInterfaceImplementations().IsEmpty ||
method.IsAccessor() ||
method.IsAnonymousFunction() ||
Expand Down