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
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix analyzer [RCS1172](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1172) ([PR](https://github.com/dotnet/roslynator/pull/1710))

## [4.14.1] - 2025-10-05

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ private static void Analyze(SyntaxNodeAnalysisContext context, SyntaxNode node)
if (!nullCheck.Success)
return;

if ((nullCheck.Style & NullCheckStyles.ComparisonToNull) != NullCheckStyles.None
&& context.SemanticModel
.GetMethodSymbol(nullCheck.NullCheckExpression)?
.ContainingType?
.SpecialType != SpecialType.System_Object)
{
return;
}

AsExpressionInfo asExpressionInfo = SyntaxInfo.AsExpressionInfo(nullCheck.Expression);

if (!asExpressionInfo.Success)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ void M(object item)
}
}
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseIsOperatorInsteadOfAsOperator)]
public async Task TestNoDiagnostic_OverloadedEqualityOperator()
{
await VerifyNoDiagnosticAsync(@"
internal class C
{
public static implicit operator C(int i) => new C();
public static bool operator ==(C left, C right) => default;
public static bool operator !=(C left, C right) => default;
public override bool Equals(object obj) => default;
public override int GetHashCode() => default;

void M(object x)
{
if (x as C != null)
{
}
}
}
");
}
}
Loading