Merge pull request #818 from hanswolff/patch-1
[mono.git] / mcs / mcs / parameter.cs
index 69ae1cf839f2a8da9cd5352f0b2fa11521f27a8f..bcd814149a28d60acc37e3c10fb9927bda02cae7 100644 (file)
@@ -394,7 +394,7 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       TypeManager.CheckTypeVariance (parameter_type,
+                       VarianceDecl.CheckTypeVariance (parameter_type,
                                (modFlags & Parameter.Modifier.RefOutMask) != 0 ? Variance.None : Variance.Contravariant,
                                rc);
 
@@ -501,7 +501,7 @@ namespace Mono.CSharp {
                                        } else {
                                                rc.Report.Error (1909, default_expr.Location,
                                                        "The DefaultParameterValue attribute is not applicable on parameters of type `{0}'",
-                                                       default_expr.Type.GetSignatureForError ()); ;
+                                                       default_expr.Type.GetSignatureForError ());
                                        }
 
                                        default_expr = null;
@@ -972,10 +972,18 @@ namespace Mono.CSharp {
                                        if (inflated_types[i] == expr.Type)
                                                continue;
 
-                                       if (expr is DefaultValueExpression)
+                                       var c = expr as Constant;
+                                       if (c != null) {
+                                               //
+                                               // It may fail we are inflating before type validation is done
+                                               //
+                                               c = Constant.ExtractConstantFromValue (inflated_types[i], c.GetValue (), expr.Location);
+                                               if (c == null)
+                                                       expr = new DefaultValueExpression (new TypeExpression (inflated_types[i], expr.Location), expr.Location);
+                                               else
+                                                       expr = c;
+                                       } else if (expr is DefaultValueExpression)
                                                expr = new DefaultValueExpression (new TypeExpression (inflated_types[i], expr.Location), expr.Location);
-                                       else if (expr is Constant)
-                                               expr = Constant.CreateConstantFromValue (inflated_types[i], ((Constant) expr).GetValue (), expr.Location);
 
                                        clone.FixedParameters[i] = new ParameterData (fp.Name, fp.ModFlags, expr);
                                }
@@ -1325,11 +1333,6 @@ namespace Mono.CSharp {
                {
                }
 
-               protected override Expression DoResolve (ResolveContext rc)
-               {
-                       return base.DoResolve (rc);
-               }
-
                public void Resolve (ResolveContext rc, Parameter p)
                {
                        var expr = Resolve (rc);
@@ -1378,6 +1381,8 @@ namespace Mono.CSharp {
                        rc.Report.Error (1750, Location,
                                "Optional parameter expression of type `{0}' cannot be converted to parameter type `{1}'",
                                type.GetSignatureForError (), parameter_type.GetSignatureForError ());
+
+                       this.expr = ErrorExpression.Instance;
                }
                
                public override object Accept (StructuralVisitor visitor)