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

Unused value assignment analysis doesn't handle ref locals #32855

Closed
sharwell opened this issue Jan 27, 2019 · 2 comments
Closed

Unused value assignment analysis doesn't handle ref locals #32855

sharwell opened this issue Jan 27, 2019 · 2 comments
Assignees
Labels
Area-IDE Bug IDE-CodeStyle Built-in analyzers, fixes, and refactorings Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@sharwell
Copy link
Member

sharwell commented Jan 27, 2019

Version Used: Visual Studio 2019 Preview 2

Found while working on coverlet-coverage/coverlet#309

Steps to Reproduce:

class Test
{
  int[] data = { 0 };

  void Method()
  {
    ref int target = ref data[0];
    target = 1;
  }
}

Expected Behavior:

IDE0059 is not reported for the assignment.

Actual Behavior:

IDE0059 is reported for the assignment.

@sharwell sharwell added Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it Area-IDE IDE-CodeStyle Built-in analyzers, fixes, and refactorings labels Jan 27, 2019
@mavasani mavasani changed the title Unused field analysis doesn't handle ref locals Unused value assignment analysis doesn't handle ref locals Jan 29, 2019
@mavasani mavasani added the 4 - In Review A fix for the issue is submitted for review. label Jan 29, 2019
mavasani added a commit to mavasani/roslyn that referenced this issue Jan 29, 2019
We need points to analysis for properly analyzing unused assignments to ref locals, which is currently not supported.
Fixes dotnet#32855
@Tragetaschen
Copy link

Does this fix this as well?

private void test()
{
    ReadOnlySequence<byte> a = default;
    var count = 0;
    foreach (var _ in a) // IDE0059 smudge here on _
        ++count;
}

@mavasani
Copy link
Contributor

Why is there a loop instead of count += a.Length? The diagnostic fires as it seems fishy for a foreach loop to never access the iteration variable.

@sharwell sharwell added Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented and removed 4 - In Review A fix for the issue is submitted for review. help wanted The issue is "up for grabs" - add a comment if you are interested in working on it labels Jan 29, 2019
@sharwell sharwell added this to the 16.0.P4 milestone Jan 29, 2019
xoofx pushed a commit to stark-lang/stark-roslyn that referenced this issue Apr 16, 2019
We need points to analysis for properly analyzing unused assignments to ref locals, which is currently not supported.
Fixes dotnet#32855
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 Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

No branches or pull requests

3 participants