-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
IParameterReferenceExpression operation not generated for parameter access in a certain cases #8884
Comments
Quick repro: Build roslyn-analyzers into RoslynDev hive and create a project with above code - you should see CA1801 (remove unused parameter) warning. |
Found couple more cases where this repros:
using System;
using System.Reflection;
class C
{
void F(int x, IDisposable o)
{
using (o)
{
int y = x; // no parameter reference received for 'x'
}
}
private object F2(Assembly assembly)
{
return (from t in assembly.GetTypes()
select t.Attributes).FirstOrDefault(); // no parameter reference received for 'assembly'
}
} |
Add more skipped tests for dotnet/roslyn#8884
This is causing lot of false reports in Analyzers.sln in roslyn-analyzers repo - we should probably test the fix for this bug against that solution. |
We get no parameter reference for parameter type if used in a string as follows: |
Yes, I also get false reports for CA1801 in interpolated strings and LINQ queries. Additionally, I see unexpected reports on parameter usage in initializers: private Panel CreateRankingsOverlay(string text)
{
return new Panel
{
Controls =
{
new AutoScalingLabel
{
Text = text,
}
}
};
} private static char AutoDetectFieldSeparator(string line)
{
var charCounts = new Dictionary<char, int>
{
{ '\t', line.Count(c => c == '\t') },
{ ';', line.Count(c => c == ';') },
{ ',', line.Count(c => c == ',') },
{ ':', line.Count(c => c == ':') },
{ '|', line.Count(c => c == '|') }
};
int highestOccurrence = charCounts.Max(pair => pair.Value);
return charCounts.First(pair => pair.Value == highestOccurrence).Key;
} |
@cston found another case for pointer expressions:
No parameter reference generated for |
* Disable "Review Unused Parameters" analyzer See dotnet/roslyn#8884 * Remove suppressions for CA1801 false positives
… nodes for whom IOperation support is not yet implemented This ensures that the analyzer driver/operation walker is able to find all the descendant IOperation nodes within these not yet implemented features. We should remove the IOperationWithChildren interface once we have designed all the IOperation APIs. TODO: Implement the VB part. Fixes dotnet#8884
Re-activating as we still have couple of cases which have not been addressed with #18976. More specifically, parameter references in delegate creation and collection initializers. |
…ssion The current IOperation API implementation of BoundDelegateCreationExpression has a bunch of issues and needs to be redesigned. This is tracked by dotnet#8897 and will be addressed post 15.3. Meanwhile, to unblock analyzers on code containing delegate creation expressions with lambda arguments, this bound node has been switched to OperationKind.None with override for Children property. Fixes the first repro case provided in dotnet#8884
It looks like the problem still exists in some scenarios:
|
And for C# as well:
|
Sample test code:
This does not repro for VB.
The text was updated successfully, but these errors were encountered: