未验证 提交 0e0ac9f2 编写于 作者: G Gen Lu 提交者: GitHub

Merge pull request #39543 from christophertrml/unnecessary-cast-information-loss-conversions

Implicit numeric casts shouldn't be recommended to be removed if doing so loses precision
......@@ -2111,6 +2111,22 @@ public A(object x)
}");
}
[WorkItem(39042, "https://github.com/dotnet/roslyn/issues/39042")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryCast)]
public async Task DontRemoveNecessaryCastForImplicitNumericCastsThatLoseInformation()
{
await TestMissingInRegularAndScriptAsync(
@"using System;
class A
{
public A(long x)
{
long y = (long)[|(double)x|];
}
}");
}
#region Interface Casts
[WorkItem(545889, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545889")]
......
......@@ -500,7 +500,8 @@ public static bool IsUnnecessaryCast(this CastExpressionSyntax cast, SemanticMod
expressionToCastType.IsImplicit &&
(expressionToCastType.IsNumeric || expressionToCastType.IsConstantExpression))
{
return true;
// Some implicit numeric conversions can cause loss of precision and must not be removed.
return !IsRequiredImplicitNumericConversion(expressionType, castType);
}
if (!castToOuterType.IsBoxing &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册