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

RS0046 code fix introduces compilation errors when names are aliased #3813

Open
sharwell opened this issue Jul 2, 2020 · 7 comments
Open
Labels
Area-Roslyn.Diagnostics.Analyzers Blocked Bug The product is not behaving according to its current intended design

Comments

@sharwell
Copy link
Member

sharwell commented Jul 2, 2020

Analyzer package

Unknown

Package Version

3.3.0-beta1.20262.5

Diagnostic ID

RS0046

Repro steps

void Method(TextSpan? selectionOpt)
{
  if (selectionOpt.HasValue)
  {
    var selection = selectionOpt.Value;
    Console.WriteLine(selection);
  }
}

Apply the code fix for RS0046.

Expected behavior

The resulting code compiles without errors.

Actual behavior

The code does not compile due to a conflict with the name selection.

@sharwell sharwell added Bug The product is not behaving according to its current intended design Area-Roslyn.Diagnostics.Analyzers labels Jul 2, 2020
@mavasani
Copy link
Contributor

mavasani commented Jul 2, 2020

Dupe of #3707. @Evangelink actually tried to implement it but couldn't figure out the right API usage - LookupSymbols seems to not provide existing symbols in scope.

@sharwell
Copy link
Member Author

sharwell commented Jul 2, 2020

💭 I'm not sure this is a duplicate. It seems related but not exactly the same.

@Evangelink
Copy link
Member

@sharwell @mavasani is there any one you would know who could help with the "correct" use of the method so we can quickly fix these cases?

@Evangelink
Copy link
Member

I did some debugging to try and understand why I don't get the right results and I have noticed that even when called from a method parameter location the LookupSymbols method only returns namespace, class and members level symbols. I do manage to retrieve the other parameters and the local variable by passing the span of the method body.

Now the question is, shall I pass the method body/expression body as a diagnostic argument to avoid the "complex" logic in the code-fix or shall I do the detection from the code-fix.

Note that there is at least one more rule that will have to reuse the logic so depending on how we implement it we might be better off with a helper method.

@sharwell
Copy link
Member Author

sharwell commented Jul 7, 2020

The first thing I would look at is how Roslyn's name suggestion completion provider avoids conflicts when suggesting names.

@Evangelink
Copy link
Member

@sharwell Do you have some usage example? I don't know this api/feature.

@Evangelink
Copy link
Member

Ping @sharwell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Roslyn.Diagnostics.Analyzers Blocked Bug The product is not behaving according to its current intended design
Projects
None yet
Development

No branches or pull requests

3 participants