Skip to content

Commit e70d186

Browse files
authored
Fix analyzer RCS1248 (#1677)
1 parent a3b471c commit e70d186

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Fix analyzer [RCS1246](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1246) ([PR](https://github.com/dotnet/roslynator/pull/1676))
13+
- Fix analyzer [RCS1248](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1248) ([PR](https://github.com/dotnet/roslynator/pull/1677))
1314

1415
## [4.14.0] - 2025-07-26
1516

src/CSharp/CSharp/Extensions/SyntaxExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,6 +2918,15 @@ public static bool IsInExpressionTree(
29182918
case SyntaxKind.GroupClause:
29192919
case SyntaxKind.SelectClause:
29202920
{
2921+
if (semanticModel
2922+
.GetTypeInfo(current, cancellationToken)
2923+
.ConvertedType?
2924+
.OriginalDefinition
2925+
.HasMetadataName(MetadataNames.System_Linq_IQueryable_T) == true)
2926+
{
2927+
return true;
2928+
}
2929+
29212930
SymbolInfo symbolInfo = semanticModel.GetSymbolInfo(current, cancellationToken);
29222931

29232932
if (IsMethodThatAcceptsExpressionAsFirstParameter(symbolInfo))

src/Tests/Analyzers.Tests/RCS1248NormalizeNullCheckTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,29 @@ void M()
209209
210210
public object P { get; }
211211
}
212+
", options: Options.AddConfigOption(ConfigOptionKeys.NullCheckStyle, ConfigOptionValues.NullCheckStyle_PatternMatching));
213+
}
214+
215+
[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.NormalizeNullCheck)]
216+
public async Task TestNoDiagnostic_ExpressionTree2()
217+
{
218+
await VerifyNoDiagnosticAsync(@"
219+
using System.Linq;
220+
221+
class C
222+
{
223+
void M()
224+
{
225+
var _ = from x in new[] { ""a"" }.AsQueryable()
226+
join yy in new[] { ""b"" }.AsQueryable()
227+
on x equals yy into y
228+
from yy in y.DefaultIfEmpty()
229+
select new
230+
{
231+
A = yy != null
232+
};
233+
}
234+
}
212235
", options: Options.AddConfigOption(ConfigOptionKeys.NullCheckStyle, ConfigOptionValues.NullCheckStyle_PatternMatching));
213236
}
214237
}

0 commit comments

Comments
 (0)