Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@giggio

Description

@giggio
Issue body actions

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"
Reactions are currently unavailable

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.