X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Fcfold.cs;h=a23a20a122cf186f500363663fb6e52710d62706;hb=9d23552efbb02fb4d6410db9fd1ce0a9ca9d08a8;hp=d2b8c0bf07a2223e366b148e557b84bfc2d7b6f9;hpb=cc9fa96a3163b4ac0b2df0726c72963017d802d6;p=mono.git diff --git a/mcs/mcs/cfold.cs b/mcs/mcs/cfold.cs index d2b8c0bf07a..a23a20a122c 100644 --- a/mcs/mcs/cfold.cs +++ b/mcs/mcs/cfold.cs @@ -20,7 +20,7 @@ namespace Mono.CSharp { // // Performs the numeric promotions on the left and right expresions - // and desposits the results on `lc' and `rc'. + // and deposits the results on `lc' and `rc'. // // On success, the types of `lc' and `rc' on output will always match, // and the pair will be one of: @@ -101,8 +101,8 @@ namespace Mono.CSharp { bool bool_res; if (lt == TypeManager.bool_type && lt == rt) { - bool lv = ((BoolConstant) left ).Value; - bool rv = ((BoolConstant) right).Value; + bool lv = (bool) left.GetValue (); + bool rv = (bool) right.GetValue (); switch (oper) { case Binary.Operator.BitwiseAnd: case Binary.Operator.LogicalAnd: @@ -254,23 +254,25 @@ namespace Mono.CSharp { break; case Binary.Operator.Addition: + if (lt == TypeManager.null_type) + return right; + + if (rt == TypeManager.null_type) + return left; + // // If both sides are strings, then concatenate, if // one is a string, and the other is not, then defer // to runtime concatenation // if (lt == TypeManager.string_type || rt == TypeManager.string_type){ - if (lt == TypeManager.string_type && rt == TypeManager.string_type) - return new StringConstant ( - ((StringConstant) left).Value + - ((StringConstant) right).Value, left.Location); + if (lt == rt) + return new StringConstant ((string)left.GetValue () + (string)right.GetValue (), + left.Location); return null; } - if (lt == TypeManager.null_type && lt == rt) - return left; - // // handle "E operator + (E x, U y)" // handle "E operator + (Y y, E x)" @@ -382,8 +384,6 @@ namespace Mono.CSharp { ((DecimalConstant) right).Value); result = new DecimalConstant (res, left.Location); - } else { - throw new Exception ( "Unexepected addition input: " + left); } } catch (OverflowException){ Error_CompileTimeOverflow (loc);