Skip to content

Commit

Permalink
Fix analyzer RCS1264 (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Sep 1, 2024
1 parent 6a85d83 commit f945094
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix analyzer [RCS1198](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1198) ([PR](https://github.com/dotnet/roslynator/pull/1501))
- Fix analyzer [RCS1214](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1214) ([PR](https://github.com/dotnet/roslynator/pull/1500))
- Fix analyzer [RCS1018](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1018) ([PR](https://github.com/dotnet/roslynator/pull/1510))
- Fix analyzer [RCS1264](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1264) ([PR](https://github.com/dotnet/roslynator/pull/1511))

## [4.12.4] - 2024-06-01

Expand Down
3 changes: 0 additions & 3 deletions src/CSharp/CSharp/CSharpTypeAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,6 @@ public static bool IsTypeObvious(ExpressionSyntax expression, ITypeSymbol? typeS
case SyntaxKind.TrueLiteralExpression:
case SyntaxKind.FalseLiteralExpression:
case SyntaxKind.ThisExpression:
{
return true;
}
case SyntaxKind.ObjectCreationExpression:
case SyntaxKind.ArrayCreationExpression:
case SyntaxKind.CastExpression:
Expand Down
16 changes: 16 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1264UseVarOrExplicitTypeTests3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,22 @@ void M()
int x = I.Parse("");
}
}
""", options: Options.AddConfigOption(ConfigOptionKeys.UseVar, ConfigOptionValues.UseVar_WhenTypeIsObvious));
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseVarOrExplicitType)]
public async Task TestNoDiagnostic_SpanWithStringLiteral()
{
await VerifyNoDiagnosticAsync("""
using System;
class C
{
void M()
{
ReadOnlySpan<char> span = "";
}
}
""", options: Options.AddConfigOption(ConfigOptionKeys.UseVar, ConfigOptionValues.UseVar_WhenTypeIsObvious));
}
}

0 comments on commit f945094

Please sign in to comment.