@@ -186,12 +186,28 @@ private static Expression ApplyBinaryExpression(Identifier op, Func<Expression,
186186 return result ;
187187 }
188188
189- //
190- // 12.4.7 Numeric promotions
191- // https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#1247-numeric-promotions
192- //
193189 private static void ApplyBinaryNumericPromotions ( Identifier op , ref Expression lhs , ref Expression rhs )
194190 {
191+ //
192+ // 12.4.7.3 Binary numeric promotions
193+ // https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#12473-binary-numeric-promotions
194+ //
195+ // Binary numeric promotion implicitly converts both operands to a common type which,
196+ // in case of the non-relational operators, also becomes the result type of the operation.
197+ // Binary numeric promotion consists of applying the following rules, in the order they appear here:
198+ //
199+ // * If either operand is of type decimal, the other operand is converted to type decimal,
200+ // or a binding-time error occurs if the other operand is of type float or double.
201+ // * Otherwise, if either operand is of type double, the other operand is converted to type double.
202+ // * Otherwise, if either operand is of type float, the other operand is converted to type float.
203+ // * Otherwise, if either operand is of type ulong, the other operand is converted to type ulong,
204+ // or a binding-time error occurs if the other operand is of type sbyte, short, int, or long.
205+ // * Otherwise, if either operand is of type long, the other operand is converted to type long.
206+ // * Otherwise, if either operand is of type uint and the other operand is of type sbyte, short, or int,
207+ // both operands are converted to type long.
208+ // * Otherwise, if either operand is of type uint, the other operand is converted to type uint.
209+ // * Otherwise, both operands are converted to type int.
210+
195211 var lhsType = lhs . Type ;
196212 var rhsType = rhs . Type ;
197213
@@ -221,8 +237,10 @@ private static void ApplyBinaryNumericPromotions(Identifier op, ref Expression l
221237
222238 if ( conversionType == typeof ( decimal ) )
223239 {
240+ //
224241 // If either operand is of type decimal, the other operand is converted to type decimal,
225242 // or a compile-time error occurs if the other operand is of type float or double.
243+ //
226244 if ( lhsType == typeof ( double )
227245 || lhsType == typeof ( float )
228246 || rhsType == typeof ( double )
@@ -231,8 +249,10 @@ private static void ApplyBinaryNumericPromotions(Identifier op, ref Expression l
231249 }
232250 else if ( conversionType == typeof ( ulong ) )
233251 {
234- // if either operand is of type ulong, the other operand is converted to type ulong,
252+ //
253+ // If either operand is of type ulong, the other operand is converted to type ulong,
235254 // or a compile-time error occurs if the other operand is of type sbyte, short, int, or long.
255+ //
236256 if ( lhsType == typeof ( sbyte )
237257 || lhsType == typeof ( short )
238258 || lhsType == typeof ( int )
@@ -245,8 +265,10 @@ private static void ApplyBinaryNumericPromotions(Identifier op, ref Expression l
245265 }
246266 else if ( conversionType == typeof ( uint ) )
247267 {
248- // if either operand is of type uint and the other operand is of type sbyte, short, or int,
268+ //
269+ // If either operand is of type uint and the other operand is of type sbyte, short, or int,
249270 // both operands are converted to type long.
271+ //
250272 if ( lhsType == typeof ( sbyte )
251273 || lhsType == typeof ( short )
252274 || lhsType == typeof ( int )
0 commit comments