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
3 changes: 2 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [CLI] Fix filtering of projects (relates to `--projects` or `--ignored-projects` parameter) ([#914](https://github.com/josefpihrt/roslynator/pull/914)).
- Refactoring "Add using directive" (RR0014) now works when file-scoped namespace is used ([#932](https://github.com/josefpihrt/roslynator/pull/932)).
- Add parentheses if necessary in a code fix for [RCS1197](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1197.md) ([#928](https://github.com/josefpihrt/roslynator/pull/928) by @karl-sjogren).
- Do not simplify default expression if it would change semantics [RCS1244](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1244.md) ([#939](https://github.com/josefpihrt/roslynator/pull/939).
- Do not simplify default expression if it would change semantics ([RCS1244](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1244.md)) ([#939](https://github.com/josefpihrt/roslynator/pull/939).
- Fix NullReferenceException in [RCS1198](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1198.md) ([#940](https://github.com/josefpihrt/roslynator/pull/940).

-----
<!-- Content below does not adhere to 'Keep a Changelog' format -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void Analyze(SyntaxNodeAnalysisContext context, in SimpleMemberInv

if (!expression.IsKind(SyntaxKind.InterpolatedStringExpression, SyntaxKind.AddExpression)
&& parameters[0].Type.IsObject()
&& context.SemanticModel.GetTypeSymbol(expression, context.CancellationToken).IsValueType)
&& context.SemanticModel.GetTypeSymbol(expression, context.CancellationToken)?.IsValueType == true)
{
DiagnosticHelpers.ReportDiagnostic(context, DiagnosticRules.AvoidBoxingOfValueType, argument);
return;
Expand Down
20 changes: 20 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1198AvoidBoxingOfValueTypeTests2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ void M()
sb.AppendFormat(""f"", i, i, i, i);
}
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.AvoidBoxingOfValueType)]
public async Task TestNoDiagnostic_NoTypeSymbol()
{
await VerifyNoDiagnosticAsync(@"
using System.Text;

class C
{
void M()
{
var f = false;

var sb = new StringBuilder();

sb.Append(f ? ""ab"" : 'c');
}
}
");
}
}
Expand Down