-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-IDEBughelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on itThe issue is "up for grabs" - add a comment if you are interested in working on it
Milestone
Description
This issue has been moved from a ticket on Developer Community.
[severity:It bothers me. A fix would be nice]
[Reproducibility conditions]
- In the c# editor, and
- An
ifstatement of the formif (<condition>) return <stateme 1>; else return <statement 2>;exists, and conditionorstatement 1orstatement 2is a checked expression (checked(<sub-statement>)) and- When “Quick actions and refactoring…” and “Convert to conditional expression” are executed for an
ifstatement.
[Expected behavior]
The if statement is converted to a conditional expression while keeping the checked expression.
[Actual operation]
Checked expressions are lost. (The checked expression checked(<sub-statement>) is converted to just <sub-statement>)
[Sample program]
using System;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
namespace Experiment01
{
internal class Program
{
[SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "<Pending>")]
private static int Main(string[] args)
{
Console.WriteLine(PlusAndEquals(int.MaxValue, int.MaxValue, int.MinValue, int.MinValue));
Console.WriteLine(Difference(int.MaxValue, int.MinValue));
return 0;
}
private static string PlusAndEquals(int x1, int x2, int y1, int y2)
{
if (checked(x1 + x2 == y1 + y2)) // If this "if" is converted into a conditional expression, it will be converted into unintended code.
return "OK";
else
return "NG";
}
private static int Difference(int x, int y)
{
if (x >= y) // If this "if" is converted into a conditional expression, it will be converted into unintended code.
return checked(x - y);
else
return 0;
}
}
}
-When converting the if statement of the PlusAndEquals method to a conditional expression-
The overflow check for x1 + x2 == y1 + y2 will no longer be performed as shown in the code below.
private static string PlusAndEquals(int x1, int x2, int y1, int y2)
{
return x1 + x2 == y1 + y2 ? "OK" : "NG";
}
-When converting the if statement of the Difference method to a conditional expression-
The overflow check for x - y will no longer be performed as shown in the code below.
private static int Difference(int x, int y)
{
return x >= y ? x - y : 0;
}
Original Comments
Feedback Bot on 11/8/2023, 11:32 PM:
(private comment, text removed)
Original Solutions
(no solutions)
juner
Metadata
Metadata
Assignees
Labels
Area-IDEBughelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on itThe issue is "up for grabs" - add a comment if you are interested in working on it
Type
Projects
Status
Completed