提交 ec94c89f 编写于 作者: A AlekseyTs

Account for an implicit conversion for the left operand of a compound...

Account for an implicit conversion for the left operand of a compound assignment while checking for usage of a Bitwise-or operator on a sign-extended operand.

Fixes #4027.
上级 d42d9b7c
......@@ -238,7 +238,16 @@ private void CheckBinaryOperator(BoundBinaryOperator node)
private void CheckCompoundAssignmentOperator(BoundCompoundAssignmentOperator node)
{
CheckForBitwiseOrSignExtend(node, node.Operator.Kind, node.Left, node.Right);
BoundExpression left = node.Left;
if (!node.Operator.Kind.IsDynamic() && !node.LeftConversion.IsIdentity && node.LeftConversion.Exists)
{
// Need to represent the implicit conversion as a node in order to be able to produce correct diagnostics.
left = new BoundConversion(left.Syntax, left, node.LeftConversion, node.Operator.Kind.IsChecked(),
explicitCastInCode: false, constantValueOpt: null, type: node.Operator.LeftType);
}
CheckForBitwiseOrSignExtend(node, node.Operator.Kind, left, node.Right);
CheckLiftedCompoundAssignment(node);
if (_inExpressionLambda)
......
......@@ -8728,5 +8728,26 @@ operator int (IntHolder ih)
operator IntHolder(int i)
'y' is 5");
}
[Fact, WorkItem(4027, "https://github.com/dotnet/roslyn/issues/4027")]
public void NotSignExtendedOperand()
{
string source = @"
class MainClass
{
public static void Main ()
{
short a = 0;
int b = 0;
a |= (short)b;
a = (short)(a | (short)b);
}
}
";
var compilation = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
compilation.VerifyDiagnostics();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册