Resolve switch cases without look aheah look-up. Fixes #12583
[mono.git] / mcs / mcs / ecore.cs
index 185c2e833e166c99ef835a543a549ffa77ea7799..dd3681529e0eb04c33be636a1d283bfb610cab05 100644 (file)
@@ -361,6 +361,8 @@ namespace Mono.CSharp {
                {
                        if (rhs == EmptyExpression.LValueMemberAccess || rhs == EmptyExpression.LValueMemberOutAccess) {
                                // Already reported as CS1612
+                       } else if (rhs == EmptyExpression.OutAccess) {
+                               rc.Report.Error (1510, loc, "A ref or out argument must be an assignable variable");
                        } else {
                                rc.Report.Error (131, loc, "The left-hand side of an assignment must be a variable, a property or an indexer");
                        }
@@ -495,10 +497,7 @@ namespace Mono.CSharp {
 
                        if (e == null) {
                                if (errors == ec.Report.Errors) {
-                                       if (out_access)
-                                               ec.Report.Error (1510, loc, "A ref or out argument must be an assignable variable");
-                                       else
-                                               Error_ValueAssignment (ec, right_side);
+                                       Error_ValueAssignment (ec, right_side);
                                }
                                return null;
                        }
@@ -512,6 +511,23 @@ namespace Mono.CSharp {
                        return e;
                }
 
+               public Constant ResolveLabelConstant (ResolveContext rc)
+               {
+                       var expr = Resolve (rc);
+                       if (expr == null)
+                               return null;
+
+                       Constant c = expr as Constant;
+                       if (c == null) {
+                               if (c.type != InternalType.ErrorType)
+                                       rc.Report.Error (150, StartLocation, "A constant value is expected");
+
+                               return null;
+                       }
+
+                       return c;
+               }
+
                public virtual void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
                {
                        rc.Module.Compiler.Report.Error (182, loc,
@@ -1537,7 +1553,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override Constant ConvertExplicitly(bool in_checked_context, TypeSpec target_type)
+               public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
                {
                        if (Child.Type == target_type)
                                return Child;
@@ -2421,15 +2437,15 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext ec)
+               public override FullNamedExpression ResolveAsTypeOrNamespace (IMemberContext mc)
                {
-                       FullNamedExpression fne = ec.LookupNamespaceOrType (Name, Arity, LookupMode.Normal, loc);
+                       FullNamedExpression fne = mc.LookupNamespaceOrType (Name, Arity, LookupMode.Normal, loc);
 
                        if (fne != null) {
                                if (fne.Type != null && Arity > 0) {
                                        if (HasTypeArguments) {
                                                GenericTypeExpr ct = new GenericTypeExpr (fne.Type, targs, loc);
-                                               if (ct.ResolveAsType (ec) == null)
+                                               if (ct.ResolveAsType (mc) == null)
                                                        return null;
 
                                                return ct;
@@ -2445,21 +2461,21 @@ namespace Mono.CSharp {
                                        return fne;
                        }
 
-                       if (Arity == 0 && Name == "dynamic" && ec.Module.Compiler.Settings.Version > LanguageVersion.V_3) {
-                               if (!ec.Module.PredefinedAttributes.Dynamic.IsDefined) {
-                                       ec.Module.Compiler.Report.Error (1980, Location,
+                       if (Arity == 0 && Name == "dynamic" && mc.Module.Compiler.Settings.Version > LanguageVersion.V_3) {
+                               if (!mc.Module.PredefinedAttributes.Dynamic.IsDefined) {
+                                       mc.Module.Compiler.Report.Error (1980, Location,
                                                "Dynamic keyword requires `{0}' to be defined. Are you missing System.Core.dll assembly reference?",
-                                               ec.Module.PredefinedAttributes.Dynamic.GetSignatureForError ());
+                                               mc.Module.PredefinedAttributes.Dynamic.GetSignatureForError ());
                                }
 
                                fne = new DynamicTypeExpr (loc);
-                               fne.ResolveAsType (ec);
+                               fne.ResolveAsType (mc);
                        }
 
                        if (fne != null)
                                return fne;
 
-                       Error_TypeOrNamespaceNotFound (ec);
+                       Error_TypeOrNamespaceNotFound (mc);
                        return null;
                }
 
@@ -3295,8 +3311,12 @@ namespace Mono.CSharp {
                        if (ExtensionExpression == null)
                                return null;
 
+                       var cand = candidates;
                        arguments.Insert (0, new Argument (ExtensionExpression, Argument.AType.ExtensionType));
                        var res = base.OverloadResolve (ec, ref arguments, ehandler ?? this, restr);
+                       
+                       // Restore candidates in case we are running in probing mode 
+                       candidates = cand;
 
                        // Store resolved argument and restore original arguments
                        if (res == null) {