Correctly type fixed buffer wrapper type. Fixes #10803
[mono.git] / mcs / mcs / ecore.cs
index 2e9ce0ee4aa55c39e4faf22fea044fc7eee21f42..720a4307a2bedadc97ad6dbae9169b9eb2c89f92 100644 (file)
@@ -3,11 +3,11 @@
 //
 // Author:
 //   Miguel de Icaza (miguel@ximian.com)
-//   Marek Safar (marek.safar@seznam.cz)
+//   Marek Safar (marek.safar@gmail.com)
 //
 // Copyright 2001, 2002, 2003 Ximian, Inc.
 // Copyright 2003-2008 Novell, Inc.
-// Copyright 2011 Xamarin Inc.
+// Copyright 2011-2012 Xamarin Inc.
 //
 //
 
@@ -225,14 +225,19 @@ namespace Mono.CSharp {
                                name, TypeManager.CSharpName (type));
                }
 
-               public static void Error_InvalidExpressionStatement (Report Report, Location loc)
+               protected virtual void Error_InvalidExpressionStatement (Report report, Location loc)
                {
-                       Report.Error (201, loc, "Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement");
+                       report.Error (201, loc, "Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement");
                }
                
-               public void Error_InvalidExpressionStatement (BlockContext ec)
+               public void Error_InvalidExpressionStatement (BlockContext bc)
                {
-                       Error_InvalidExpressionStatement (ec.Report, loc);
+                       Error_InvalidExpressionStatement (bc.Report, loc);
+               }
+
+               public void Error_InvalidExpressionStatement (Report report)
+               {
+                       Error_InvalidExpressionStatement (report, loc);
                }
 
                public static void Error_VoidInvalidInTheContext (Location loc, Report Report)
@@ -323,14 +328,7 @@ namespace Mono.CSharp {
                public virtual void Error_ValueAssignment (ResolveContext rc, Expression rhs)
                {
                        if (rhs == EmptyExpression.LValueMemberAccess || rhs == EmptyExpression.LValueMemberOutAccess) {
-                               rc.Report.SymbolRelatedToPreviousError (type);
-                               if (rc.CurrentInitializerVariable != null) {
-                                       rc.Report.Error (1918, loc, "Members of value type `{0}' cannot be assigned using a property `{1}' object initializer",
-                                               type.GetSignatureForError (), GetSignatureForError ());
-                               } else {
-                                       rc.Report.Error (1612, loc, "Cannot modify a value type return value of `{0}'. Consider storing the value in a temporary variable",
-                                               GetSignatureForError ());
-                               }
+                               // Already reported as CS1612
                        } else {
                                rc.Report.Error (131, loc, "The left-hand side of an assignment must be a variable, a property or an indexer");
                        }
@@ -367,6 +365,27 @@ namespace Mono.CSharp {
                        }
                }
 
+               //
+               // Implements identical simple name and type-name resolution
+               //
+               public Expression ProbeIdenticalTypeName (ResolveContext rc, Expression left, SimpleName name)
+               {
+                       var t = left.Type;
+                       if (t.Kind == MemberKind.InternalCompilerType || t is ElementTypeSpec || t.Arity > 0)
+                               return left;
+
+                       // In a member access of the form E.I, if E is a single identifier, and if the meaning of E as a simple-name is
+                       // a constant, field, property, local variable, or parameter with the same type as the meaning of E as a type-name
+
+                       if (left is MemberExpr || left is VariableReference) {
+                               var identical_type = rc.LookupNamespaceOrType (name.Name, 0, LookupMode.Probing, loc) as TypeExpr;
+                               if (identical_type != null && identical_type.Type == left.Type)
+                                       return identical_type;
+                       }
+
+                       return left;
+               }
+
                public virtual string GetSignatureForError ()
                {
                        return type.GetDefinition ().GetSignatureForError ();
@@ -682,7 +701,7 @@ namespace Mono.CSharp {
                                        if ((member.Modifiers & Modifiers.OVERRIDE) != 0 && member.Kind != MemberKind.Event)
                                                continue;
 
-                                       if ((member.Modifiers & Modifiers.BACKING_FIELD) != 0)
+                                       if ((member.Modifiers & Modifiers.BACKING_FIELD) != 0 || member.Kind == MemberKind.Operator)
                                                continue;
 
                                        if ((arity > 0 || (restrictions & MemberLookupRestrictions.ExactArity) != 0) && member.Arity != arity)
@@ -721,6 +740,23 @@ namespace Mono.CSharp {
                                        if (non_method == null || member is MethodSpec || non_method.IsNotCSharpCompatible) {
                                                non_method = member;
                                        } else if (!errorMode && !member.IsNotCSharpCompatible) {
+                                               //
+                                               // Interface members that are hidden by class members are removed from the set when T is a type parameter and
+                                               // T has both an effective base class other than object and a non-empty effective interface set.
+                                               //
+                                               // The spec has more complex rules but we simply remove all members declared in an interface declaration.
+                                               //
+                                               var tps = queried_type as TypeParameterSpec;
+                                               if (tps != null && tps.HasTypeConstraint) {
+                                                       if (non_method.DeclaringType.IsClass && member.DeclaringType.IsInterface)
+                                                               continue;
+
+                                                       if (non_method.DeclaringType.IsInterface && member.DeclaringType.IsInterface) {
+                                                               non_method = member;
+                                                               continue;
+                                                       }
+                                               }
+
                                                ambig_non_method = member;
                                        }
                                }
@@ -1031,15 +1067,57 @@ namespace Mono.CSharp {
                        if (es == null)
                                Error_InvalidExpressionStatement (ec);
 
-                       if (ec.CurrentAnonymousMethod is AsyncInitializer && !(e is Assign) &&
-                               (e.Type.IsGenericTask || e.Type == ec.Module.PredefinedTypes.Task.TypeSpec)) {
-                               ec.Report.Warning (4014, 1, e.Location,
-                                       "The statement is not awaited and execution of current method continues before the call is completed. Consider using `await' operator");
+                       //
+                       // This is quite expensive warning, try to limit the damage
+                       //
+                       if (MemberAccess.IsValidDotExpression (e.Type) && !(e is Assign || e is Await)) {
+                               WarningAsyncWithoutWait (ec, e);
                        }
 
                        return es;
                }
 
+               static void WarningAsyncWithoutWait (BlockContext bc, Expression e)
+               {
+                       if (bc.CurrentAnonymousMethod is AsyncInitializer) {
+                               var awaiter = new AwaitStatement.AwaitableMemberAccess (e) {
+                                       ProbingMode = true
+                               };
+
+                               //
+                               // Need to do full resolve because GetAwaiter can be extension method
+                               // available only in this context
+                               //
+                               var mg = awaiter.Resolve (bc) as MethodGroupExpr;
+                               if (mg == null)
+                                       return;
+
+                               var arguments = new Arguments (0);
+                               mg = mg.OverloadResolve (bc, ref arguments, null, OverloadResolver.Restrictions.ProbingOnly);
+                               if (mg == null)
+                                       return;
+
+                               //
+                               // Use same check rules as for real await
+                               //
+                               var awaiter_definition = bc.Module.GetAwaiter (mg.BestCandidateReturnType);
+                               if (!awaiter_definition.IsValidPattern || !awaiter_definition.INotifyCompletion)
+                                       return;
+
+                               bc.Report.Warning (4014, 1, e.Location,
+                                       "The statement is not awaited and execution of current method continues before the call is completed. Consider using `await' operator");
+                               return;
+                       }
+
+                       var inv = e as Invocation;
+                       if (inv != null && inv.MethodGroup != null && inv.MethodGroup.BestCandidate.IsAsync) {
+                               // The warning won't be reported for imported methods to maintain warning compatiblity with csc 
+                               bc.Report.Warning (4014, 1, e.Location,
+                                       "The statement is not awaited and execution of current method continues before the call is completed. Consider using `await' operator or calling `Wait' method");
+                               return;
+                       }
+               }
+
                /// <summary>
                ///   Requests the expression to be emitted in a `statement'
                ///   context.  This means that no new value is left on the
@@ -2294,10 +2372,16 @@ namespace Mono.CSharp {
 
                        var ns_candidates = ctx.Module.GlobalRootNamespace.FindTypeNamespaces (ctx, Name, Arity);
                        if (ns_candidates != null) {
-                               string usings = string.Join ("' or `", ns_candidates);
-                               report.Error (246, loc,
-                                       "The type or namespace name `{0}' could not be found. Are you missing `{1}' using directive?",
-                                       Name, usings);
+                               if (ctx is UsingAliasNamespace.AliasContext) {
+                                       report.Error (246, loc,
+                                               "The type or namespace name `{1}' could not be found. Consider using fully qualified name `{0}.{1}'",
+                                               ns_candidates[0], Name);
+                               } else {
+                                       string usings = string.Join ("' or `", ns_candidates.ToArray ());
+                                       report.Error (246, loc,
+                                               "The type or namespace name `{0}' could not be found. Are you missing `{1}' using directive?",
+                                               Name, usings);
+                               }
                        } else {
                                report.Error (246, loc,
                                        "The type or namespace name `{0}' could not be found. Are you missing an assembly reference?",
@@ -2775,7 +2859,7 @@ namespace Mono.CSharp {
                                //
                                TypeSpec[] targs = null;
                                if (method.DeclaringType != InstanceExpression.Type) {
-                                       var base_override = MemberCache.FindMember (InstanceExpression.Type, new MemberFilter (method), BindingRestriction.InstanceOnly) as MethodSpec;
+                                       var base_override = MemberCache.FindMember (InstanceExpression.Type, new MemberFilter (method), BindingRestriction.InstanceOnly | BindingRestriction.OverrideOnly) as MethodSpec;
                                        if (base_override != null && base_override.DeclaringType != method.DeclaringType) {
                                                if (base_override.IsGeneric)
                                                        targs = method.TypeArguments;
@@ -2920,28 +3004,31 @@ namespace Mono.CSharp {
                                member.GetSignatureForError (), qualifier.GetSignatureForError (), rc.CurrentType.GetSignatureForError ());
                }
 
-               //
-               // Implements identicial simple name and type-name
-               //
-               public Expression ProbeIdenticalTypeName (ResolveContext rc, Expression left, SimpleName name)
+               public bool ResolveInstanceExpression (ResolveContext rc, Expression rhs)
                {
-                       var t = left.Type;
-                       if (t.Kind == MemberKind.InternalCompilerType || t is ElementTypeSpec || t.Arity > 0)
-                               return left;
+                       if (!ResolveInstanceExpressionCore (rc, rhs))
+                               return false;
 
-                       // In a member access of the form E.I, if E is a single identifier, and if the meaning of E as a simple-name is
-                       // a constant, field, property, local variable, or parameter with the same type as the meaning of E as a type-name
+                       //
+                       // Check intermediate value modification which won't have any effect
+                       //
+                       if (rhs != null && InstanceExpression.Type.IsStruct &&
+                               (InstanceExpression is PropertyExpr || InstanceExpression is IndexerExpr || InstanceExpression is Invocation)) {
 
-                       if (left is MemberExpr || left is VariableReference) {
-                               var identical_type = rc.LookupNamespaceOrType (name.Name, 0, LookupMode.Probing, loc) as TypeExpr;
-                               if (identical_type != null && identical_type.Type == left.Type)
-                                       return identical_type;
+                               if (rc.CurrentInitializerVariable != null) {
+                                       rc.Report.Error (1918, loc, "Members of value type `{0}' cannot be assigned using a property `{1}' object initializer",
+                                               InstanceExpression.Type.GetSignatureForError (), InstanceExpression.GetSignatureForError ());
+                               } else {
+                                       rc.Report.Error (1612, loc,
+                                               "Cannot modify a value type return value of `{0}'. Consider storing the value in a temporary variable",
+                                               InstanceExpression.GetSignatureForError ());
+                               }
                        }
 
-                       return left;
+                       return true;
                }
 
-               public bool ResolveInstanceExpression (ResolveContext rc, Expression rhs)
+               bool ResolveInstanceExpressionCore (ResolveContext rc, Expression rhs)
                {
                        if (IsStatic) {
                                if (InstanceExpression != null) {
@@ -3005,7 +3092,7 @@ namespace Mono.CSharp {
 
                        var me = InstanceExpression as MemberExpr;
                        if (me != null) {
-                               me.ResolveInstanceExpression (rc, rhs);
+                               me.ResolveInstanceExpressionCore (rc, rhs);
 
                                // Using this check to detect probing instance expression resolve
                                if (!rc.OmitStructFlowAnalysis) {
@@ -3183,8 +3270,12 @@ namespace Mono.CSharp {
                        }
 
                        var me = ExtensionExpression as MemberExpr;
-                       if (me != null)
+                       if (me != null) {
                                me.ResolveInstanceExpression (ec, null);
+                               var fe = me as FieldExpr;
+                               if (fe != null)
+                                       fe.Spec.MemberDefinition.SetIsUsed ();
+                       }
 
                        InstanceExpression = null;
                        return this;
@@ -3454,6 +3545,11 @@ namespace Mono.CSharp {
                                best_candidate_return = best_candidate.ReturnType;
                        }
 
+                       if (best_candidate.IsGeneric && (restr & OverloadResolver.Restrictions.ProbingOnly) == 0 && TypeParameterSpec.HasAnyTypeParameterConstrained (best_candidate.GenericDefinition)) {
+                               ConstraintChecker cc = new ConstraintChecker (ec);
+                               cc.CheckAll (best_candidate.GetGenericMethodDefinition (), best_candidate.TypeArguments, best_candidate.Constraints, loc);
+                       }
+
                        //
                        // Additional check for possible imported base override method which
                        // could not be done during IsOverrideMethodBaseTypeAccessible
@@ -3755,7 +3851,9 @@ namespace Mono.CSharp {
                                if (!TypeSpecComparer.Equals (p_m.Parameters.Types, q_m.Parameters.Types))
                                        return 0;
 
+                               var orig_p = p;
                                p = p_m.ReturnType;
+                               var orig_q = q;
                                q = q_m.ReturnType;
 
                                //
@@ -3772,21 +3870,30 @@ namespace Mono.CSharp {
                                        return p.Kind != MemberKind.Void ? 1: 0;
                                }
 
+                               var am = (AnonymousMethodExpression) a.Expr;
+
                                //
                                // When anonymous method is an asynchronous, and P has a return type Task<Y1>, and Q has a return type Task<Y2>
                                // better conversion is performed between underlying types Y1 and Y2
                                //
                                if (p.IsGenericTask || q.IsGenericTask) {
-                                       var async_am = a.Expr as AnonymousMethodExpression;
-                                       if (async_am != null && async_am.Block.IsAsync) {
-
-                                               if (p.IsGenericTask != q.IsGenericTask) {
-                                                       return 0;
-                                               }
-
+                                       if (am.Block.IsAsync && p.IsGenericTask && q.IsGenericTask) {
                                                q = q.TypeArguments[0];
                                                p = p.TypeArguments[0];
                                        }
+                               } else if (q != p) {
+                                       //
+                                       // LAMESPEC: Lambda expression returning dynamic type has identity (better) conversion to delegate returning object type
+                                       //
+                                       if (q.BuiltinType == BuiltinTypeSpec.Type.Object) {
+                                               var am_rt = am.InferReturnType (ec, null, orig_q);
+                                               if (am_rt != null && am_rt.BuiltinType == BuiltinTypeSpec.Type.Dynamic)
+                                                       return 2;
+                                       } else if (p.BuiltinType == BuiltinTypeSpec.Type.Object) {
+                                               var am_rt = am.InferReturnType (ec, null, orig_p);
+                                               if (am_rt != null && am_rt.BuiltinType == BuiltinTypeSpec.Type.Dynamic)
+                                                       return 1;
+                                       }
                                }
 
                                //
@@ -3991,19 +4098,20 @@ namespace Mono.CSharp {
                        //
                        //  Foo (int i) is better than Foo (int i, long l = 0)
                        //  Foo (params int[] args) is better than Foo (int i = 0, params int[] args)
+                       //  Foo (string s, params string[] args) is better than Foo (params string[] args)
                        //
                        // Prefer non-optional version
                        //
                        // LAMESPEC: Specification claims this should be done at last but the opposite is true
                        //
                        if (candidate_params == best_params && candidate_pd.Count != best_pd.Count) {
-                               if (candidate_pd.Count >= best_pd.Count)
-                                       return false;
-
                                if (j < candidate_pd.Count && candidate_pd.FixedParameters[j].HasDefaultValue)
                                        return false;
 
-                               return true;
+                               if (j < best_pd.Count && best_pd.FixedParameters[j].HasDefaultValue)
+                                       return true;
+
+                               return candidate_pd.Count >= best_pd.Count;
                        }
 
                        //
@@ -4065,6 +4173,32 @@ namespace Mono.CSharp {
                        return false;
                }
 
+               static bool CheckInflatedArguments (MethodSpec ms)
+               {
+                       if (!TypeParameterSpec.HasAnyTypeParameterTypeConstrained (ms.GenericDefinition))
+                               return true;
+
+                       // Setup constraint checker for probing only
+                       ConstraintChecker cc = new ConstraintChecker (null);
+
+                       var mp = ms.Parameters.Types;
+                       for (int i = 0; i < mp.Length; ++i) {
+                               var type = mp[i] as InflatedTypeSpec;
+                               if (type == null)
+                                       continue;
+
+                               var targs = type.TypeArguments;
+                               if (targs.Length == 0)
+                                       continue;
+
+                               // TODO: Checking inflated MVAR arguments should be enough
+                               if (!cc.CheckAll (type.GetDefinition (), targs, type.Constraints, Location.Null))
+                                       return false;
+                       }
+
+                       return true;
+               }
+
                public static void Error_ConstructorMismatch (ResolveContext rc, TypeSpec type, int argCount, Location loc)
                {
                        rc.Report.Error (1729, loc,
@@ -4117,6 +4251,9 @@ namespace Mono.CSharp {
                                        } else if (arg_count > param_count) {
                                                int args_gap = System.Math.Abs (arg_count - param_count);
                                                return int.MaxValue - 10000 + args_gap;
+                                       } else if (arg_count < param_count - optional_count) {
+                                               int args_gap = System.Math.Abs (param_count - optional_count - arg_count);
+                                               return int.MaxValue - 10000 + args_gap;
                                        }
                                } else if (arg_count != param_count) {
                                        int args_gap = System.Math.Abs (arg_count - param_count);
@@ -4220,9 +4357,6 @@ namespace Mono.CSharp {
                        TypeSpec[] ptypes;
                        var ms = candidate as MethodSpec;
                        if (ms != null && ms.IsGeneric) {
-                               // Setup constraint checker for probing only
-                               ConstraintChecker cc = new ConstraintChecker (null);
-
                                if (type_arguments != null) {
                                        var g_args_count = ms.Arity;
                                        if (g_args_count != type_arguments.Count)
@@ -4268,14 +4402,12 @@ namespace Mono.CSharp {
                                        if (i_args.Length != 0) {
                                                ms = ms.MakeGenericMethod (ec, i_args);
                                        }
-
-                                       cc.IgnoreInferredDynamic = true;
                                }
 
                                //
                                // Type arguments constraints have to match for the method to be applicable
                                //
-                               if (!cc.CheckAll (ms.GetGenericMethodDefinition (), ms.TypeArguments, ms.Constraints, loc)) {
+                               if (!CheckInflatedArguments (ms)) {
                                        candidate = ms;
                                        return int.MaxValue - 25000;
                                }
@@ -4296,7 +4428,8 @@ namespace Mono.CSharp {
                                }
 
                                candidate = ms;
-                               ptypes = ms.Parameters.Types;
+                               pd = ms.Parameters;
+                               ptypes = pd.Types;
                        } else {
                                if (type_arguments != null)
                                        return int.MaxValue - 15000;
@@ -4324,18 +4457,15 @@ namespace Mono.CSharp {
                                        // if the type matches
                                        //
                                        Expression e = fp.DefaultValue;
-                                       if (!(e is Constant) || e.Type.IsGenericOrParentIsGeneric || e.Type.IsGenericParameter) {
-                                               //
-                                               // LAMESPEC: No idea what the exact rules are for System.Reflection.Missing.Value instead of null
-                                               //
-                                               if (e == EmptyExpression.MissingValue && ptypes[i].BuiltinType == BuiltinTypeSpec.Type.Object || ptypes[i].BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
-                                                       e = new MemberAccess (new MemberAccess (new MemberAccess (
-                                                               new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Reflection", loc), "Missing", loc), "Value", loc);
-                                               } else {
-                                                       e = new DefaultValueExpression (new TypeExpression (ptypes [i], loc), loc);
+                                       if (e != null) {
+                                               e = ResolveDefaultValueArgument (ec, ptypes[i], e, loc);
+                                               if (e == null) {
+                                                       // Restore for possible error reporting
+                                                       for (int ii = i; ii < arg_count; ++ii)
+                                                               arguments.RemoveAt (i);
+
+                                                       return (arg_count - i) * 2 + 1;
                                                }
-
-                                               e = e.Resolve (ec);
                                        }
 
                                        if ((fp.ModFlags & Parameter.Modifier.CallerMask) != 0) {
@@ -4428,6 +4558,31 @@ namespace Mono.CSharp {
                        return 0;
                }
 
+               public static Expression ResolveDefaultValueArgument (ResolveContext ec, TypeSpec ptype, Expression e, Location loc)
+               {
+                       if (e is Constant && e.Type == ptype)
+                               return e;
+
+                       //
+                       // LAMESPEC: No idea what the exact rules are for System.Reflection.Missing.Value instead of null
+                       //
+                       if (e == EmptyExpression.MissingValue && ptype.BuiltinType == BuiltinTypeSpec.Type.Object || ptype.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
+                               e = new MemberAccess (new MemberAccess (new MemberAccess (
+                                       new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Reflection", loc), "Missing", loc), "Value", loc);
+                       } else if (e is Constant) {
+                               //
+                               // Handles int to int? conversions, DefaultParameterValue check
+                               //
+                               e = Convert.ImplicitConversionStandard (ec, e, ptype, loc);
+                               if (e == null)
+                                       return null;
+                       } else {
+                               e = new DefaultValueExpression (new TypeExpression (ptype, loc), loc);
+                       }
+
+                       return e.Resolve (ec);
+               }
+
                //
                // Tests argument compatibility with the parameter
                // The possible return values are
@@ -4502,7 +4657,7 @@ namespace Mono.CSharp {
                                        return p;
                                if (specific == ac_q.Element)
                                        return q;
-                       } else if (TypeManager.IsGenericType (p)) {
+                       } else if (p.IsGeneric && q.IsGeneric) {
                                var pargs = TypeManager.GetTypeArguments (p);
                                var qargs = TypeManager.GetTypeArguments (q);
 
@@ -4738,6 +4893,17 @@ namespace Mono.CSharp {
                                                args [0].Type.GetSignatureForError (), best_candidate.Name, best_candidate.GetSignatureForError ());
                                }
 
+                               //
+                               // Check type constraints only when explicit type arguments are used
+                               //
+                               if (best_candidate.IsGeneric && type_arguments != null) {
+                                       MethodSpec bc = best_candidate as MethodSpec;
+                                       if (bc != null && TypeParameterSpec.HasAnyTypeParameterConstrained (bc.GenericDefinition)) {
+                                               ConstraintChecker cc = new ConstraintChecker (rc);
+                                               cc.CheckAll (bc.GetGenericMethodDefinition (), bc.TypeArguments, bc.Constraints, loc);
+                                       }
+                               }
+
                                BestCandidateIsDynamic = true;
                                return null;
                        }
@@ -4771,7 +4937,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       if (invocable_member != null) {
+                       if (invocable_member != null && !IsProbingOnly) {
                                rc.Report.SymbolRelatedToPreviousError (best_candidate);
                                rc.Report.SymbolRelatedToPreviousError (invocable_member);
                                rc.Report.Warning (467, 2, loc, "Ambiguity between method `{0}' and invocable non-method `{1}'. Using method group",
@@ -4791,13 +4957,18 @@ namespace Mono.CSharp {
                                return null;
 
                        //
-                       // Check ObsoleteAttribute on the best method
+                       // Don't run possibly expensive checks in probing mode
                        //
-                       ObsoleteAttribute oa = best_candidate.GetAttributeObsolete ();
-                       if (oa != null && !rc.IsObsolete)
-                               AttributeTester.Report_ObsoleteMessage (oa, best_candidate.GetSignatureForError (), loc, rc.Report);
+                       if (!IsProbingOnly && !rc.IsInProbingMode) {
+                               //
+                               // Check ObsoleteAttribute on the best method
+                               //
+                               ObsoleteAttribute oa = best_candidate.GetAttributeObsolete ();
+                               if (oa != null && !rc.IsObsolete)
+                                       AttributeTester.Report_ObsoleteMessage (oa, best_candidate.GetSignatureForError (), loc, rc.Report);
 
-                       best_candidate.MemberDefinition.SetIsUsed ();
+                               best_candidate.MemberDefinition.SetIsUsed ();
+                       }
 
                        args = best_candidate_args;
                        return (T) best_candidate;
@@ -4820,7 +4991,7 @@ namespace Mono.CSharp {
                        if (a is CollectionElementInitializer.ElementInitializerArgument) {
                                ec.Report.SymbolRelatedToPreviousError (method);
                                if ((expected_par.FixedParameters[idx].ModFlags & Parameter.Modifier.RefOutMask) != 0) {
-                                       ec.Report.Error (1954, loc, "The best overloaded collection initalizer method `{0}' cannot have 'ref', or `out' modifier",
+                                       ec.Report.Error (1954, loc, "The best overloaded collection initalizer method `{0}' cannot have `ref' or `out' modifier",
                                                TypeManager.CSharpSignature (method));
                                        return;
                                }
@@ -4854,7 +5025,12 @@ namespace Mono.CSharp {
                                        p2 = paramType.GetSignatureForErrorIncludingAssemblyName ();
                                }
 
-                               ec.Report.Error (1503, loc,
+                               if ((mod & Parameter.Modifier.RefOutMask) != 0) {
+                                       p1 = Parameter.GetModifierSignature (a.Modifier) + " " + p1;
+                                       p2 = Parameter.GetModifierSignature (a.Modifier) + " " + p2;
+                               }
+
+                               ec.Report.Error (1503, a.Expr.Location,
                                        "Argument `#{0}' cannot convert `{1}' expression to type `{2}'", index, p1, p2);
                        }
                }
@@ -5142,7 +5318,7 @@ namespace Mono.CSharp {
                        var c = constant.GetConstant (rc);
 
                        // Creates reference expression to the constant value
-                       return Constant.CreateConstant (constant.MemberType, c.GetValue (), loc);
+                       return Constant.CreateConstantFromValue (constant.MemberType, c.GetValue (), loc);
                }
 
                public override void Emit (EmitContext ec)
@@ -5296,6 +5472,8 @@ namespace Mono.CSharp {
 
                protected override Expression DoResolve (ResolveContext ec)
                {
+                       spec.MemberDefinition.SetIsUsed ();
+
                        return DoResolve (ec, null);
                }
 
@@ -5433,6 +5611,11 @@ namespace Mono.CSharp {
                
                override public Expression DoResolveLValue (ResolveContext ec, Expression right_side)
                {
+                       if (spec is FixedFieldSpec) {
+                               // It could be much better error message but we want to be error compatible
+                               Error_ValueAssignment (ec, right_side);
+                       }
+
                        Expression e = DoResolve (ec, right_side);
 
                        if (e == null)
@@ -5515,8 +5698,6 @@ namespace Mono.CSharp {
                {
                        bool is_volatile = (spec.Modifiers & Modifiers.VOLATILE) != 0;
 
-                       spec.MemberDefinition.SetIsUsed ();
-                       
                        if (IsStatic){
                                if (is_volatile)
                                        ec.Emit (OpCodes.Volatile);
@@ -5697,6 +5878,8 @@ namespace Mono.CSharp {
        //
        sealed class PropertyExpr : PropertyOrIndexerExpr<PropertySpec>
        {
+               Arguments arguments;
+
                public PropertyExpr (PropertySpec spec, Location l)
                        : base (l)
                {
@@ -5708,9 +5891,10 @@ namespace Mono.CSharp {
 
                protected override Arguments Arguments {
                        get {
-                               return null;
+                               return arguments;
                        }
                        set {
+                               arguments = value;
                        }
                }
 
@@ -5867,7 +6051,7 @@ namespace Mono.CSharp {
                                        }
                                }
                        } else {
-                               args = new Arguments (1);
+                               args = arguments == null ? new Arguments (1) : arguments;
 
                                if (leave_copy) {
                                        source.Emit (ec);
@@ -5917,6 +6101,22 @@ namespace Mono.CSharp {
                        }
 
                        DoBestMemberChecks (rc, best_candidate);
+
+                       // Handling of com-imported properties with any number of default property parameters
+                       if (best_candidate.HasGet && !best_candidate.Get.Parameters.IsEmpty) {
+                               var p = best_candidate.Get.Parameters;
+                               arguments = new Arguments (p.Count);
+                               for (int i = 0; i < p.Count; ++i) {
+                                       arguments.Add (new Argument (OverloadResolver.ResolveDefaultValueArgument (rc, p.Types [i], p.FixedParameters [i].DefaultValue, loc)));
+                               }
+                       } else if (best_candidate.HasSet && best_candidate.Set.Parameters.Count > 1) {
+                               var p = best_candidate.Set.Parameters;
+                               arguments = new Arguments (p.Count - 1);
+                               for (int i = 0; i < p.Count - 1; ++i) {
+                                       arguments.Add (new Argument (OverloadResolver.ResolveDefaultValueArgument (rc, p.Types [i], p.FixedParameters [i].DefaultValue, loc)));
+                               }
+                       }
+
                        return this;
                }
 
@@ -5996,11 +6196,6 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       // if the property/indexer returns a value type, and we try to set a field in it
-                       if (right_side == EmptyExpression.LValueMemberAccess || right_side == EmptyExpression.LValueMemberOutAccess) {
-                               Error_ValueAssignment (ec, right_side);
-                       }
-
                        if (eclass == ExprClass.Unresolved) {
                                var expr = OverloadResolve (ec, right_side);
                                if (expr == null)
@@ -6360,8 +6555,9 @@ namespace Mono.CSharp {
                        // Don't capture temporary variables except when using
                        // state machine redirection and block yields
                        //
-                       if (ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod.IsIterator &&
-                               ec.CurrentBlock.Explicit.HasYield && ec.IsVariableCapturingRequired) {
+                       if (ec.CurrentAnonymousMethod != null && ec.CurrentAnonymousMethod is StateMachineInitializer &&
+                               (ec.CurrentBlock.Explicit.HasYield || ec.CurrentBlock.Explicit.HasAwait) &&
+                               ec.IsVariableCapturingRequired) {
                                AnonymousMethodStorey storey = li.Block.Explicit.CreateAnonymousMethodStorey (ec);
                                storey.CaptureLocalVariable (ec, li);
                        }