+ if (default_expr != null)
+ default_expr = ResolveDefaultExpression (rc);
+ }
+
+ Expression ResolveDefaultExpression (ResolveContext rc)
+ {
+ default_expr = default_expr.Resolve (rc);
+ if (default_expr == null)
+ return null;
+
+ if (!(default_expr is Constant || default_expr is DefaultValueExpression)) {
+ if (TypeManager.IsNullableType (parameter_type)) {
+ rc.Compiler.Report.Error (1770, default_expr.Location,
+ "The expression being assigned to nullable optional parameter `{0}' must be default value",
+ Name);
+ } else {
+ rc.Compiler.Report.Error (1736, default_expr.Location,
+ "The expression being assigned to optional parameter `{0}' must be a constant or default value",
+ Name);
+ }
+
+ return null;
+ }
+
+ if (TypeManager.IsEqual (default_expr.Type, parameter_type))
+ return default_expr;
+
+ if (TypeManager.IsNullableType (parameter_type)) {
+ if (Convert.ImplicitNulableConversion (rc, default_expr, parameter_type) != null)
+ return default_expr;
+ } else {
+ var res = Convert.ImplicitConversionStandard (rc, default_expr, parameter_type, default_expr.Location);
+ if (res != null) {
+ if (!default_expr.IsNull && TypeManager.IsReferenceType (parameter_type) && parameter_type != TypeManager.string_type) {
+ rc.Compiler.Report.Error (1763, default_expr.Location,
+ "Optional parameter `{0}' of type `{1}' can only be initialized with `null'",
+ Name, GetSignatureForError ());
+
+ return null;
+ }
+
+ return res;
+ }
+ }
+
+ rc.Compiler.Report.Error (1750, Location,
+ "Optional parameter expression of type `{0}' cannot be converted to parameter type `{1}'",
+ TypeManager.CSharpName (default_expr.Type), GetSignatureForError ());
+
+ return null;
+ }
+
+ public bool HasDefaultValue {
+ get { return default_expr != null; }