diff --git a/ChangeLog.md b/ChangeLog.md index c889f8fea5..f869ad7cd2 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix analyzer [RCS1194](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1194) ([PR](https://github.com/dotnet/roslynator/pull/1733)) + ## [4.15.0] - 2025-12-14 ### Added diff --git a/src/Analyzers/CSharp/Analysis/ImplementExceptionConstructorsAnalyzer.cs b/src/Analyzers/CSharp/Analysis/ImplementExceptionConstructorsAnalyzer.cs index 84bb5cd046..6f15604baf 100644 --- a/src/Analyzers/CSharp/Analysis/ImplementExceptionConstructorsAnalyzer.cs +++ b/src/Analyzers/CSharp/Analysis/ImplementExceptionConstructorsAnalyzer.cs @@ -67,6 +67,11 @@ private static void AnalyzeNamedType(SymbolAnalysisContext context, INamedTypeSy var classDeclaration = (ClassDeclarationSyntax)symbol.GetSyntax(context.CancellationToken); +#if ROSLYN_4_0 + if (classDeclaration.ParameterList is not null) + return; +#endif + DiagnosticHelpers.ReportDiagnostic(context, DiagnosticRules.ImplementExceptionConstructors, classDeclaration.Identifier); } diff --git a/src/Tests/Analyzers.Tests/RCS1194ImplementExceptionConstructorsTests.cs b/src/Tests/Analyzers.Tests/RCS1194ImplementExceptionConstructorsTests.cs index 61ad4a10a6..b350aad104 100644 --- a/src/Tests/Analyzers.Tests/RCS1194ImplementExceptionConstructorsTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1194ImplementExceptionConstructorsTests.cs @@ -38,6 +38,16 @@ public C(string message, Exception innerException) : base(message, innerExceptio { } } +"); + } + + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.ImplementExceptionConstructors)] + public async Task Test_PrimaryConstructor() + { + await VerifyNoDiagnosticAsync(@" +using System; + +class MyException (string message) : Exception(message); "); } }