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 S2386 & S3887 FP: should not be raised for FrozenDictionary and FrozenSet #8638

Closed
T-Emile opened this issue Jan 30, 2024 · 1 comment · Fixed by #8652
Closed

Fix S2386 & S3887 FP: should not be raised for FrozenDictionary and FrozenSet #8638

T-Emile opened this issue Jan 30, 2024 · 1 comment · Fixed by #8652
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@T-Emile
Copy link

T-Emile commented Jan 30, 2024

Description

S2386 and S3887 should not be raised for types FrozenDictionary and FrozenSet.

Repro steps

public class Test
{
    public static readonly FrozenDictionary<string, string> FrozenDictionaryTest = new Dictionary<string, string>().ToFrozenDictionary();
    public static readonly FrozenSet<string> FrozenSetTest = new HashSet<string>().ToFrozenSet();
}

Expected behavior

No warnings should be raised.

Actual behavior

Two warnings are raised for both fields:

S2386: Use an immutable collection or reduce the accessibility of the public static field 'FrozenDictionaryTest'.
S3887: Use an immutable collection or reduce the accessibility of the non-private readonly field 'FrozenDictionaryTest'.

@martin-strecker-sonarsource
Copy link
Contributor

Hello @T-Emile
Thank you for reporting this FP. We have added a reproducer and a fix in #8652.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
3 participants