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: Do not suggest IReadOnlyCollection<T> interface instead of IReadOnlyList<T> if collection items are accessed by index #813

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

Comments

@antrv
Copy link

antrv commented Oct 9, 2017

Description

Wrong message about using IReadOnlyCollection interface instead of IReadOnlyList if collection items are accessed by index:
Consider using more general type 'System.Collections.Generic.IReadOnlyCollection' instead of 'System.Collections.Generic.IReadOnlyList'.

Repro steps

public static long ParseNonNegativeLong(this IReadOnlyList<string> arguments, int index, string name)
{
    if (arguments == null || index < 0 || index >= arguments.Count)
        throw new JobArgumentException(index, name);

    if (!long.TryParse(arguments[index], out long result))
        throw new JobArgumentException(index, name, "Expected number.");

    return result;
}

Expected behavior

No message.

Actual behavior

There is the message from the analyzer:
Consider using more general type 'System.Collections.Generic.IReadOnlyCollection' instead of 'System.Collections.Generic.IReadOnlyList'.

Related information

  • SonarC# 6.4.1.3596
  • Visual Studio 15.3.5
@antrv antrv changed the title Wrong message about using IReadOnlyCollection<T> interface instead of IReadOnlyList<T> if collection items is accessed by index Wrong message about using IReadOnlyCollection<T> interface instead of IReadOnlyList<T> if collection items are accessed by index Oct 9, 2017
@Evangelink Evangelink added Area: Rules Type: False Positive Rule IS triggered when it shouldn't be. labels Oct 13, 2017
@Evangelink
Copy link
Contributor

Hi @antrv ,
Thanks for the feedback! This is indeed a wrong suggestion and we will try to fix it soon.

@Evangelink Evangelink changed the title Wrong message about using IReadOnlyCollection<T> interface instead of IReadOnlyList<T> if collection items are accessed by index Fix S3242: Do not suggest IReadOnlyCollection<T> interface instead of IReadOnlyList<T> if collection items are accessed by index Oct 13, 2017
@michalb-sonar michalb-sonar added this to the 6.6 milestone Oct 16, 2017
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