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

Fix S3242: Rule should not report when more general type doesn't have indexer #640

Closed
vitaliyzhukov opened this issue Aug 2, 2017 · 1 comment
Assignees
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@vitaliyzhukov
Copy link

Description

Rule S3242 triggers for types with indexer, base types of which don't have one. In case described below IList has indexer and ICollection doesn't.

Repro steps

public class Foo
{
    public void MethodOne(IList list)
    {
        if (list.Count > 0)
        {
            Console.WriteLine(list[0]);
        }
    }

    public void MethodTwo(IList<Foo> list)
    {
        if (list.Count > 0)
        {
            Console.WriteLine(list[0]);
        }
    }
}

Expected behavior

Rule should not trigger.

Actual behavior

Rule triggers with following messages:

For 'MethodOne':

"Consider using more general type 'System.Collections.ICollection' instead of 'System.Collections.IList'."

For 'MethodTwo':

"Consider using more general type 'System.Collections.Generic.ICollection<MyProject.Foo>' instead of 'System.Collections.Generic.IList<MyProject.Foo>'."

Related information

  • SonarC# Version: v6.2.0.2536
  • Visual Studio Version: VS2015, VS 2017
@Evangelink
Copy link
Contributor

@michalb-sonar I will let you handle this one when you get back from holiday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

3 participants