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

BUG on CC0043 and CC0092 (ChangeAnyToAll) when invocation has elvis operator #613

Closed
giggio opened this issue Dec 2, 2015 · 2 comments
Closed

Comments

@giggio
Copy link
Member

giggio commented Dec 2, 2015

Here is the test case that will fail:

using System;
using System.Linq;
class TypeSymbol
{
    public System.Collections.Generic.IList<int> AllInterfaces { get; set; }
}
class TypeName
{
    void Foo()
    {
        var typeSymbol = new TypeSymbol();
        if (!typeSymbol?.AllInterfaces.Any(i => i.ToString() == "") ?? true) return;
    }
}

Both CC0043 and CC0092 will crash with an NullReferenceException when the Any or All invocation is complex, composed of more than one Member Access. So, instead of A.Any, which works, A.B.Any will fail. But only when composed with an elvis operator, like A?.B.Any.

This is happening at the UnusedParametersAnalyzer.cs, line 153. (See it here).

Here is the code that is causing the analysis to fail, from UnusedParametersAnalyzer.cs:

if (!typeSymbol?.AllInterfaces.Any(i => i.ToString() == "System.Runtime.Serialization.ISerializable") ?? true) return false;

The error is being raised at line 62 (see it here):

var otherInvocationSymbol = semanticModel.GetSpeculativeSymbolInfo(invocation.SpanStart, otherInvocation, SpeculativeBindingOption.BindAsExpression);

These are the variable values at that point:

invocation.ToString()
".AllInterfaces.Any(i => i.ToString() == \"System.Runtime.Serialization.ISerializable\")"
otherInvocation.ToString()
".AllInterfaces.All(i => i.ToString() == \"System.Runtime.Serialization.ISerializable\")"
invocation.Expression.ToString()
".AllInterfaces.Any"
@giggio
Copy link
Member Author

giggio commented Dec 19, 2015

I was working on the fix, and I can't repro. It is closed.

@giggio giggio closed this as completed Dec 19, 2015
@giggio giggio removed this from the 1.0.0 milestone Dec 19, 2015
@giggio giggio removed their assignment Dec 19, 2015
@giggio giggio self-assigned this Dec 30, 2015
@giggio giggio added this to the 1.0.0 milestone Dec 30, 2015
@giggio
Copy link
Member Author

giggio commented Dec 30, 2015

Reopening, found a way to repro.

@giggio giggio changed the title BUG on CC0043 and CC0092 (ChangeAnyToAll) when invocation is complex BUG on CC0043 and CC0092 (ChangeAnyToAll) when invocation is has elvis operator Dec 30, 2015
giggio added a commit to giggio/code-cracker that referenced this issue Dec 31, 2015
Diagnostic ids CC0043 and CC0092
Closes code-cracker#613
@giggio giggio reopened this Dec 31, 2015
@giggio giggio changed the title BUG on CC0043 and CC0092 (ChangeAnyToAll) when invocation is has elvis operator BUG on CC0043 and CC0092 (ChangeAnyToAll) when invocation has elvis operator Dec 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant