提交 559701b8 编写于 作者: D David Wengier

Don't suggest that casts are unnecessary when no conversion exists.

上级 58cfc997
......@@ -4492,7 +4492,7 @@ void M()
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryCast)]
public async Task DontOfferToRemoveCastFormObjectToStruct()
public async Task DontOfferToRemoveCastWhereNoConversionExists()
{
await TestMissingInRegularAndScriptAsync(
@"
......
......@@ -393,6 +393,12 @@ public static bool IsUnnecessaryCast(this CastExpressionSyntax cast, SemanticMod
var expressionToCastType = semanticModel.ClassifyConversion(cast.SpanStart, cast.Expression, castType, isExplicitInSource: true);
var outerType = GetOuterCastType(cast, semanticModel, out var parentIsOrAsExpression) ?? castTypeInfo.ConvertedType;
// If there is no conversion then there will be a compiler error, but offering the code fix before that is confusing, so jump out.
if (!expressionToCastType.Exists)
{
return false;
}
// Simple case: If the conversion from the inner expression to the cast type is identity,
// the cast can be removed.
if (expressionToCastType.IsIdentity)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册