Skip to content

Commit

Permalink
Fix RCS1206 (dotnet#1049)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored and JochemHarmes committed Oct 30, 2023
1 parent 9e8957f commit 4b161af
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix ([RCS1097](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1097.md)) ([#1037](https://github.com/JosefPihrt/Roslynator/pull/1037)).
- Do not report ([RCS1170](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1170.md)) when `Microsoft.AspNetCore.Components.InjectAttribute` is used ([#1046](https://github.com/JosefPihrt/Roslynator/pull/1046)).
- Fix ([RCS1235](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1235.md)) ([#1047](https://github.com/JosefPihrt/Roslynator/pull/1047)).
- Fix ([RCS1206](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1206.md)) ([#1049](https://github.com/JosefPihrt/Roslynator/pull/1049)).

## [4.2.0] - 2022-11-27

Expand Down
1 change: 1 addition & 0 deletions src/Analyzers/CSharp/Analysis/SimplifyNullCheckAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ private static void Analyze(

if (typeSymbol?.IsErrorType() == false
&& (typeSymbol.IsReferenceType || typeSymbol.IsValueType)
&& (!typeSymbol.IsValueType || !typeSymbol.IsRefLikeType)
&& (semanticModel.IsDefaultValue(typeSymbol, whenNull, cancellationToken)
|| IsDefaultOfNullableStruct(typeSymbol, whenNull, semanticModel, cancellationToken))
&& !CSharpUtility.ContainsOutArgumentWithLocalOrParameter(whenNotNull, semanticModel, cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,29 @@ void M2(Expression<Func<DateTime?, DateTime?>> p)
{
}
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseConditionalAccessInsteadOfConditionalExpression)]
public async Task TestNoDiagnostic_ReadOnlyRefStruct()
{
await VerifyNoDiagnosticAsync(@"
using System;
#nullable enable
class C
{
static ReadOnlySpan<byte> GetData(IDummy? dummy)
{
return dummy is not null ? dummy.Data : default;
}
interface IDummy
{
ReadOnlySpan<byte> Data { get; }
}
}
");
}
}

0 comments on commit 4b161af

Please sign in to comment.