Skip to content

Commit f214e3e

Browse files
authored
Fix analyzer RCS1264 (#1604)
1 parent 498bb29 commit f214e3e

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
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 refactoring 'Change accessibility' ([RR0186](https://josefpihrt.github.io/docs/roslynator/refactorings/RR0186)) ([PR](https://github.com/dotnet/roslynator/pull/1599))
13+
- Fix analyzer [RCS1264](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1264) ([PR](https://github.com/dotnet/roslynator/pull/1604))
1314

1415
### Changed
1516

src/Analyzers/CSharp/Analysis/UseVarOrExplicitTypeAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private static void AnalyzeVariableDeclaration(SyntaxNodeAnalysisContext context
4848
}
4949
else if (style == TypeStyle.Explicit)
5050
{
51-
if (CSharpTypeAnalysis.IsImplicitThatCanBeExplicit(variableDeclaration, context.SemanticModel, TypeAppearance.Obvious, context.CancellationToken))
51+
if (CSharpTypeAnalysis.IsImplicitThatCanBeExplicit(variableDeclaration, context.SemanticModel, context.CancellationToken))
5252
ReportImplicitToExplicit(context, variableDeclaration.Type);
5353
}
5454
else if (style == TypeStyle.ImplicitWhenTypeIsObvious)

src/Tests/Analyzers.Tests/RCS1264UseVarOrExplicitTypeTests2.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,36 @@ void M()
162162
", options: Options.AddConfigOption(ConfigOptionKeys.UseVar, ConfigOptionValues.UseVar_Never));
163163
}
164164

165+
[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseVarOrExplicitType)]
166+
public async Task Test_NotObviousExpression()
167+
{
168+
await VerifyDiagnosticAndFixAsync(@"
169+
using System.Threading.Tasks;
170+
using System.Collections.Generic;
171+
172+
class C
173+
{
174+
void M()
175+
{
176+
[|var|] x1 = string.Empty;
177+
[|var|] x2 = Task.FromResult(string.Empty);
178+
}
179+
}
180+
", @"
181+
using System.Threading.Tasks;
182+
using System.Collections.Generic;
183+
184+
class C
185+
{
186+
void M()
187+
{
188+
string x1 = string.Empty;
189+
Task<string> x2 = Task.FromResult(string.Empty);
190+
}
191+
}
192+
", options: Options.AddConfigOption(ConfigOptionKeys.UseVar, ConfigOptionValues.UseVar_Never));
193+
}
194+
165195
[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseVarOrExplicitType)]
166196
public async Task TestNoDiagnostic_ForEach_DeclarationExpression()
167197
{

0 commit comments

Comments
 (0)