提交 4c88abf0 编写于 作者: C Chris Tramel

An implicit numeric cast is only unnecessary if it doesn't have the chance to lose information.

上级 74d326f8
......@@ -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.
先完成此消息的编辑!
想要评论请 注册