2004-12-22 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / mcs / expression.cs
index d355686f5b6956584d17b4ceb72d7a17bfb51ac8..e23aec28400a75423d15debf20216691bddeb8aa 100644 (file)
@@ -217,6 +217,10 @@ namespace Mono.CSharp {
                                e = new IntConstant (-((ShortConstant) expr).Value);
                        else if (expr is UShortConstant)
                                e = new IntConstant (-((UShortConstant) expr).Value);
+                       else if (expr is SByteConstant)
+                               e = new IntConstant (-((SByteConstant) expr).Value);
+                       else if (expr is ByteConstant)
+                               e = new IntConstant (-((ByteConstant) expr).Value);
                        return e;
                }
 
@@ -237,7 +241,7 @@ namespace Mono.CSharp {
                                
                        case Operator.UnaryNegation:
                                result = TryReduceNegative (e);
-                               return true;
+                               return result != null;
                                
                        case Operator.LogicalNot:
                                if (expr_type != TypeManager.bool_type) {
@@ -2693,7 +2697,7 @@ namespace Mono.CSharp {
                                ((oper == Operator.LogicalAnd && (bool)lc.GetValue () == false) ||
                                 (oper == Operator.LogicalOr && (bool)lc.GetValue () == true))) {
 
-                               // TODO: make a sence to resolve unreachable expression as we do for statement
+                               // TODO: make a sense to resolve unreachable expression as we do for statement
                                Report.Warning (429, 4, loc, "Unreachable expression code detected");
                                return left;
                        }
@@ -3525,13 +3529,12 @@ namespace Mono.CSharp {
                                }
                        }
 
+                       // Dead code optimalization
                        if (expr is BoolConstant){
                                BoolConstant bc = (BoolConstant) expr;
 
-                               if (bc.Value)
-                                       return trueExpr;
-                               else
-                                       return falseExpr;
+                               Report.Warning (429, 4, bc.Value ? falseExpr.Location : trueExpr.Location, "Unreachable expression code detected");
+                               return bc.Value ? trueExpr : falseExpr;
                        }
 
                        return this;
@@ -8585,6 +8588,12 @@ namespace Mono.CSharp {
                                UnsafeError (loc);
                                return null;
                        }
+
+                       if (type.IsArray && (type.GetElementType () == TypeManager.arg_iterator_type ||
+                               type.GetElementType () == TypeManager.typed_reference_type)) {
+                               Report.Error (611, loc, "Array elements cannot be of type '{0}'", TypeManager.CSharpName (type.GetElementType ()));
+                               return null;
+                       }
                        
                        eclass = ExprClass.Type;
                        return this;