Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix analyzer [RCS1182](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1182) ([PR](https://github.com/dotnet/roslynator/pull/1502))
- Fix analyzer [RCS1198](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1198) ([PR](https://github.com/dotnet/roslynator/pull/1501))

## [4.12.4] - 2024-06-01

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ public override void Initialize(AnalysisContext context)
{
base.Initialize(context);

context.RegisterSyntaxNodeAction(f => AnalyzeInterpolation(f), SyntaxKind.Interpolation);
context.RegisterCompilationStartAction(startContext =>
{
INamedTypeSymbol exceptionSymbol = startContext.Compilation.GetTypeByMetadataName("System.Runtime.CompilerServices.DefaultInterpolatedStringHandler");

if (exceptionSymbol is null)
startContext.RegisterSyntaxNodeAction(f => AnalyzeInterpolation(f), SyntaxKind.Interpolation);
});
}

private static void AnalyzeInterpolation(SyntaxNodeAnalysisContext context)
Expand Down
60 changes: 0 additions & 60 deletions src/Tests/Analyzers.Tests/RCS1198AvoidBoxingOfValueTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,66 +12,6 @@ public class RCS1198AvoidBoxingOfValueTypeTests : AbstractCSharpDiagnosticVerifi
{
public override DiagnosticDescriptor Descriptor { get; } = DiagnosticRules.AvoidBoxingOfValueType;

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AvoidBoxingOfValueType)]
public async Task Test_Interpolation()
{
await VerifyDiagnosticAndFixAsync("""
using System;

class C
{
public TimeSpan P { get; }

void M()
{
var c = new C();

var x = $"{[|c?.P.TotalMilliseconds|]}";
}
}
""", """
using System;

class C
{
public TimeSpan P { get; }

void M()
{
var c = new C();

var x = $"{(c?.P.TotalMilliseconds).ToString()}";
}
}
""");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AvoidBoxingOfValueType)]
public async Task Test_Interpolation_NullableType()
{
await VerifyDiagnosticAndFixAsync("""
class C
{
void M()
{
int? i = null;

string s = $"{[|i|]}";
}
}
""", """
class C
{
void M()
{
int? i = null;

string s = $"{i?.ToString()}";
}
}
""");
}

// https://github.com/dotnet/roslyn/pull/35006
[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AvoidBoxingOfValueType)]
public async Task TestNoDiagnostic_StringConcatenation()
Expand Down