2005-03-23 Lluis Sanchez Gual <lluis@novell.com>
[mono.git] / mcs / bmcs / statement.cs
index df0ba63808e3ad1c3ce29b5672793959be85d387..45a2fb20e35007fc64af94dee35182639e30e391 100644 (file)
@@ -584,7 +584,7 @@ namespace Mono.CSharp {
                                        return false;
 
                                if (Expr.Type != ec.ReturnType) {
-                                       Expr = Convert.ImplicitConversionRequired (
+                                       Expr = Convert.WideningConversionRequired (
                                                ec, Expr, ec.ReturnType, loc);
                                        if (Expr == null)
                                                return false;
@@ -646,6 +646,7 @@ namespace Mono.CSharp {
                                label.AddUsageVector (ec.CurrentBranching.CurrentUsageVector);
 
                        ec.CurrentBranching.CurrentUsageVector.Goto ();
+                       label.AddReference ();
 
                        return true;
                }
@@ -718,7 +719,6 @@ namespace Mono.CSharp {
                {
                        ec.CurrentBranching.Label (vectors);
 
-                       referenced = true;
 
                        return true;
                }
@@ -732,6 +732,11 @@ namespace Mono.CSharp {
                        LabelTarget (ec);
                        ec.ig.MarkLabel (label);
                }
+
+               public void AddReference ()
+               {
+                       referenced = true;
+               }
        }
        
 
@@ -2390,34 +2395,39 @@ namespace Mono.CSharp {
                        // conversions, we have to report an error
                        //
                        Expression converted = null;
-                       foreach (Type tt in allowed_types){
-                               Expression e;
-                               
-                               e = Convert.ImplicitUserConversion (ec, Expr, tt, loc);
-                               if (e == null)
-                                       continue;
 
-                               //
-                               // Ignore over-worked ImplicitUserConversions that do
-                               // an implicit conversion in addition to the user conversion.
-                               // 
-                               if (e is UserCast){
-                                       UserCast ue = e as UserCast;
-
-                                       if (ue.Source != Expr)
-                                               e = null;
-                               }
+                       //
+                       // VB.NET has no notion of User defined conversions
+                       //
+
+//                     foreach (Type tt in allowed_types){
+//                             Expression e;
                                
-                               if (converted != null){
-                                       Report.ExtraInformation (
-                                               loc,
-                                               String.Format ("reason: more than one conversion to an integral type exist for type {0}",
-                                                              TypeManager.CSharpName (Expr.Type)));
-                                       return null;
-                               } else {
-                                       converted = e;
-                               }
-                       }
+//                             e = Convert.ImplicitUserConversion (ec, Expr, tt, loc);
+//                             if (e == null)
+//                                     continue;
+
+//                             //
+//                             // Ignore over-worked ImplicitUserConversions that do
+//                             // an implicit conversion in addition to the user conversion.
+//                             // 
+//                             if (e is UserCast){
+//                                     UserCast ue = e as UserCast;
+
+//                                     if (ue.Source != Expr)
+//                                             e = null;
+//                             }
+                               
+//                             if (converted != null){
+//                                     Report.ExtraInformation (
+//                                             loc,
+//                                             String.Format ("reason: more than one conversion to an integral type exist for type {0}",
+//                                                            TypeManager.CSharpName (Expr.Type)));
+//                                     return null;
+//                             } else {
+//                                     converted = e;
+//                             }
+//                     }
                        return converted;
                }
 
@@ -3436,7 +3446,7 @@ namespace Mono.CSharp {
                                        //
                                        ArrayPtr array_ptr = new ArrayPtr (e, loc);
                                        
-                                       Expression converted = Convert.ImplicitConversionRequired (
+                                       Expression converted = Convert.WideningConversionRequired (
                                                ec, array_ptr, vi.VariableType, loc);
                                        if (converted == null)
                                                return false;
@@ -3466,7 +3476,7 @@ namespace Mono.CSharp {
                                // For other cases, flag a `this is already fixed expression'
                                //
                                if (e is LocalVariableReference || e is ParameterReference ||
-                                   Convert.ImplicitConversionExists (ec, e, vi.VariableType)){
+                                   Convert.WideningConversionExists (ec, e, vi.VariableType)){
                                    
                                        Report.Error (245, loc, "right hand expression is already fixed, no need to use fixed statement ");
                                        return false;
@@ -3536,7 +3546,7 @@ namespace Mono.CSharp {
                                        ig.Emit (OpCodes.Stloc, pinned_string);
 
                                        Expression sptr = new StringPtr (pinned_string, loc);
-                                       Expression converted = Convert.ImplicitConversionRequired (
+                                       Expression converted = Convert.WideningConversionRequired (
                                                ec, sptr, vi.VariableType, loc);
                                        
                                        if (converted == null)
@@ -3839,7 +3849,7 @@ namespace Mono.CSharp {
                                        continue;
                                }
 
-                               converted_vars [i] = Convert.ImplicitConversionRequired (
+                               converted_vars [i] = Convert.WideningConversionRequired (
                                        ec, var, TypeManager.idisposable_type, loc);
 
                                if (converted_vars [i] == null)
@@ -3871,7 +3881,7 @@ namespace Mono.CSharp {
                bool ResolveExpression (EmitContext ec)
                {
                        if (!TypeManager.ImplementsInterface (expr_type, TypeManager.idisposable_type)){
-                               conv = Convert.ImplicitConversionRequired (
+                               conv = Convert.WideningConversionRequired (
                                        ec, expr, TypeManager.idisposable_type, loc);
 
                                if (conv == null)
@@ -4165,7 +4175,7 @@ namespace Mono.CSharp {
                        // Although it is not as important in this case, as the type
                        // will not likely be object (what the enumerator will return).
                        //
-                       conv = Convert.ExplicitConversion (ec, empty, var_type, loc);
+                       conv = Convert.WideningAndNarrowingConversion (ec, empty, var_type, loc);
                        if (conv == null)
                                ok = false;