Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix analyzer RCS1264 #1511

Merged
merged 3 commits into from
Sep 1, 2024
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
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));
}
}