Exemple #1
0
        protected virtual void Error_InvalidArguments(ResolveContext ec, Location loc, int idx, MethodSpec method,
            Argument a, AParametersCollection expected_par, TypeSpec paramType)
        {
            ExtensionMethodGroupExpr emg = this as ExtensionMethodGroupExpr;

            if (a is CollectionElementInitializer.ElementInitializerArgument) {
                ec.Report.SymbolRelatedToPreviousError (method);
                if ((expected_par.FixedParameters [idx].ModFlags & Parameter.Modifier.ISBYREF) != 0) {
                    ec.Report.Error (1954, loc, "The best overloaded collection initalizer method `{0}' cannot have 'ref', or `out' modifier",
                        TypeManager.CSharpSignature (method));
                    return;
                }
                ec.Report.Error (1950, loc, "The best overloaded collection initalizer method `{0}' has some invalid arguments",
                      TypeManager.CSharpSignature (method));
            } else if (TypeManager.IsDelegateType (method.DeclaringType)) {
                ec.Report.Error (1594, loc, "Delegate `{0}' has some invalid arguments",
                    TypeManager.CSharpName (method.DeclaringType));
            } else {
                ec.Report.SymbolRelatedToPreviousError (method);
                if (emg != null) {
                    ec.Report.Error (1928, loc,
                        "Type `{0}' does not contain a member `{1}' and the best extension method overload `{2}' has some invalid arguments",
                        emg.ExtensionExpression.GetSignatureForError (),
                        emg.Name, TypeManager.CSharpSignature (method));
                } else {
                    ec.Report.Error (1502, loc, "The best overloaded method match for `{0}' has some invalid arguments",
                        TypeManager.CSharpSignature (method));
                }
            }

            Parameter.Modifier mod = idx >= expected_par.Count ? 0 : expected_par.FixedParameters [idx].ModFlags;

            string index = (idx + 1).ToString ();
            if (((mod & (Parameter.Modifier.REF | Parameter.Modifier.OUT)) ^
                (a.Modifier & (Parameter.Modifier.REF | Parameter.Modifier.OUT))) != 0) {
                if ((mod & Parameter.Modifier.ISBYREF) == 0)
                    ec.Report.Error (1615, loc, "Argument `#{0}' does not require `{1}' modifier. Consider removing `{1}' modifier",
                        index, Parameter.GetModifierSignature (a.Modifier));
                else
                    ec.Report.Error (1620, loc, "Argument `#{0}' is missing `{1}' modifier",
                        index, Parameter.GetModifierSignature (mod));
            } else {
                string p1 = a.GetSignatureForError ();
                string p2 = TypeManager.CSharpName (paramType);

                if (p1 == p2) {
                    ec.Report.ExtraInformation (loc, "(equally named types possibly from different assemblies in previous ");
                    ec.Report.SymbolRelatedToPreviousError (a.Expr.Type);
                    ec.Report.SymbolRelatedToPreviousError (paramType);
                }

                if (idx == 0 && emg != null) {
                    ec.Report.Error (1929, loc,
                        "Extension method instance type `{0}' cannot be converted to `{1}'", p1, p2);
                } else {
                    ec.Report.Error (1503, loc,
                        "Argument `#{0}' cannot convert `{1}' expression to type `{2}'", index, p1, p2);
                }
            }
        }