Skip to content

Commit dd6c4c4

Browse files
authored
Fix RCS1244 (#1007)
1 parent 3c0ee27 commit dd6c4c4

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-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 [RCS1084](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1084.md) ([#1006](https://github.com/josefpihrt/roslynator/pull/1006)).
13+
- Fix [RCS1244](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1244.md) ([#1007](https://github.com/josefpihrt/roslynator/pull/1007)).
1314

1415
## [4.2.0] - 2022-11-27
1516

src/Analyzers/CSharp/Analysis/DefaultExpressionAnalyzer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ public static void AnalyzeDefaultExpression(SyntaxNodeAnalysisContext context)
107107
if (parent.IsParentKind(SyntaxKind.ObjectInitializerExpression))
108108
return;
109109

110+
if (parent is BinaryExpressionSyntax coalesceExpression
111+
&& coalesceExpression.Left == defaultExpression)
112+
{
113+
return;
114+
}
115+
110116
TypeInfo typeInfo = context.SemanticModel.GetTypeInfo(expression, context.CancellationToken);
111117

112118
if (!SymbolEqualityComparer.Default.Equals(typeInfo.Type, typeInfo.ConvertedType))

src/Tests/Analyzers.Tests/RCS1244SimplifyDefaultExpressionTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,22 @@ void M()
490490
};
491491
}
492492
}
493+
");
494+
}
495+
496+
[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.SimplifyDefaultExpression)]
497+
public async Task TestNoDiagnostic_LambdaExpression2()
498+
{
499+
await VerifyNoDiagnosticAsync(@"
500+
using System;
501+
502+
class C
503+
{
504+
T M<T>()
505+
{
506+
return default(T) ?? (T)Convert.ChangeType("""", typeof(T));
507+
}
508+
}
493509
");
494510
}
495511
}

0 commit comments

Comments
 (0)