From 68bd2db5efe70fe09a082185ed5c29ce1d09f972 Mon Sep 17 00:00:00 2001 From: Antonio Aversa Date: Thu, 28 Sep 2023 09:15:36 +0200 Subject: [PATCH] S4275: add repro for #8101 --- .../Rules/PropertiesAccessCorrectFieldTest.cs | 16 ++++++++++------ .../PropertiesAccessCorrectField.CSharp12.cs | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 analyzers/tests/SonarAnalyzer.UnitTest/TestCases/PropertiesAccessCorrectField.CSharp12.cs diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/PropertiesAccessCorrectFieldTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/PropertiesAccessCorrectFieldTest.cs index c644d84d795..f7c72f4bca4 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Rules/PropertiesAccessCorrectFieldTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Rules/PropertiesAccessCorrectFieldTest.cs @@ -31,33 +31,37 @@ public class PropertiesAccessCorrectFieldTest [TestMethod] public void PropertiesAccessCorrectField_CS() => - builderCS.AddPaths(@"PropertiesAccessCorrectField.cs").AddReferences(AdditionalReferences).Verify(); + builderCS.AddPaths("PropertiesAccessCorrectField.cs").AddReferences(AdditionalReferences).Verify(); [TestMethod] public void PropertiesAccessCorrectField_CSharp8() => - builderCS.AddPaths(@"PropertiesAccessCorrectField.CSharp8.cs").WithOptions(ParseOptionsHelper.FromCSharp8).Verify(); + builderCS.AddPaths("PropertiesAccessCorrectField.CSharp8.cs").WithOptions(ParseOptionsHelper.FromCSharp8).Verify(); #if NET [TestMethod] public void PropertiesAccessCorrectField_CSharp9() => - builderCS.AddPaths(@"PropertiesAccessCorrectField.CSharp9.cs").WithOptions(ParseOptionsHelper.FromCSharp9).Verify(); + builderCS.AddPaths("PropertiesAccessCorrectField.CSharp9.cs").WithOptions(ParseOptionsHelper.FromCSharp9).Verify(); + + [TestMethod] + public void PropertiesAccessCorrectField_CSharp12() => + builderCS.AddPaths("PropertiesAccessCorrectField.CSharp12.cs").WithOptions(ParseOptionsHelper.FromCSharp12).Verify(); #else [TestMethod] public void PropertiesAccessCorrectField_CS_NetFramework() => - builderCS.AddPaths(@"PropertiesAccessCorrectField.NetFramework.cs").AddReferences(AdditionalReferences).Verify(); + builderCS.AddPaths("PropertiesAccessCorrectField.NetFramework.cs").AddReferences(AdditionalReferences).Verify(); [TestMethod] public void PropertiesAccessCorrectField_VB_NetFramework() => - builderVB.AddPaths(@"PropertiesAccessCorrectField.NetFramework.vb").AddReferences(AdditionalReferences).Verify(); + builderVB.AddPaths("PropertiesAccessCorrectField.NetFramework.vb").AddReferences(AdditionalReferences).Verify(); #endif [TestMethod] public void PropertiesAccessCorrectField_VB() => - builderVB.AddPaths(@"PropertiesAccessCorrectField.vb").AddReferences(AdditionalReferences).Verify(); + builderVB.AddPaths("PropertiesAccessCorrectField.vb").AddReferences(AdditionalReferences).Verify(); private static IEnumerable AdditionalReferences => NuGetMetadataReference.MvvmLightLibs("5.4.1.1") diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/PropertiesAccessCorrectField.CSharp12.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/PropertiesAccessCorrectField.CSharp12.cs new file mode 100644 index 00000000000..a06ae023131 --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/PropertiesAccessCorrectField.CSharp12.cs @@ -0,0 +1,14 @@ +// https://github.com/SonarSource/sonar-dotnet/issues/8101 +namespace Repro_8101 +{ + public class SomeClass(object y) + { + object x; + + public object Y + { + get { return x; } // FN + set { x ??= value; } // FN + } + } +}