Error1599() public static méthode

public static Error1599 ( Mono.CSharp.Location loc, System.TypeSpec t, Report Report ) : void
loc Mono.CSharp.Location
t System.TypeSpec
Report Report
Résultat void
Exemple #1
0
        protected override bool DoDefineMembers()
        {
            var builtin_types = Compiler.BuiltinTypes;

            var ctor_parameters = ParametersCompiled.CreateFullyResolved(
                new [] {
                new Parameter(new TypeExpression(builtin_types.Object, Location), "object", Parameter.Modifier.NONE, null, Location),
                new Parameter(new TypeExpression(builtin_types.IntPtr, Location), "method", Parameter.Modifier.NONE, null, Location)
            },
                new [] {
                builtin_types.Object,
                builtin_types.IntPtr
            }
                );

            Constructor = new Constructor(this, Constructor.ConstructorName,
                                          Modifiers.PUBLIC, null, ctor_parameters, Location);
            Constructor.Define();

            //
            // Here the various methods like Invoke, BeginInvoke etc are defined
            //
            // First, call the `out of band' special method for
            // defining recursively any types we need:
            //
            var p = parameters;

            if (!p.Resolve(this))
            {
                return(false);
            }

            //
            // Invoke method
            //

            // Check accessibility
            foreach (var partype in p.Types)
            {
                if (!IsAccessibleAs(partype))
                {
                    Report.SymbolRelatedToPreviousError(partype);
                    Report.Error(59, Location,
                                 "Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'",
                                 partype.GetSignatureForError(), GetSignatureForError());
                }
            }

            var ret_type = ReturnType.ResolveAsType(this);

            if (ret_type == null)
            {
                return(false);
            }

            //
            // We don't have to check any others because they are all
            // guaranteed to be accessible - they are standard types.
            //
            if (!IsAccessibleAs(ret_type))
            {
                Report.SymbolRelatedToPreviousError(ret_type);
                Report.Error(58, Location,
                             "Inconsistent accessibility: return type `" +
                             ret_type.GetSignatureForError() + "' is less " +
                             "accessible than delegate `" + GetSignatureForError() + "'");
                return(false);
            }

            CheckProtectedModifier();

            if (Compiler.Settings.StdLib && ret_type.IsSpecialRuntimeType)
            {
                Method.Error1599(Location, ret_type, Report);
                return(false);
            }

            VarianceDecl.CheckTypeVariance(ret_type, Variance.Covariant, this);

            var resolved_rt = new TypeExpression(ret_type, Location);

            InvokeBuilder = new Method(this, resolved_rt, MethodModifiers, new MemberName(InvokeMethodName), p, null);
            InvokeBuilder.Define();

            //
            // Don't emit async method for compiler generated delegates (e.g. dynamic site containers)
            //
            if (!IsCompilerGenerated)
            {
                DefineAsyncMethods(resolved_rt);
            }

            return(true);
        }
Exemple #2
0
        protected override bool DoDefineMembers()
        {
            if (IsGeneric)
            {
                foreach (TypeParameter type_param in TypeParameters)
                {
                    if (!type_param.Resolve(this))
                    {
                        return(false);
                    }
                }

                foreach (TypeParameter type_param in TypeParameters)
                {
                    if (!type_param.DefineType(this))
                    {
                        return(false);
                    }
                }
            }

            member_cache = new MemberCache(TypeManager.multicast_delegate_type, this);

            // FIXME: POSSIBLY make this static, as it is always constant
            //
            Type [] const_arg_types = new Type [2];
            const_arg_types [0] = TypeManager.object_type;
            const_arg_types [1] = TypeManager.intptr_type;

            const MethodAttributes ctor_mattr = MethodAttributes.RTSpecialName | MethodAttributes.SpecialName |
                                                MethodAttributes.HideBySig | MethodAttributes.Public;

            ConstructorBuilder = TypeBuilder.DefineConstructor(ctor_mattr,
                                                               CallingConventions.Standard,
                                                               const_arg_types);

            ConstructorBuilder.DefineParameter(1, ParameterAttributes.None, "object");
            ConstructorBuilder.DefineParameter(2, ParameterAttributes.None, "method");
            //
            // HACK because System.Reflection.Emit is lame
            //
            IParameterData [] fixed_pars = new IParameterData [] {
                new ParameterData("object", Parameter.Modifier.NONE),
                new ParameterData("method", Parameter.Modifier.NONE)
            };

            AParametersCollection const_parameters = new ParametersImported(
                fixed_pars,
                new Type[] { TypeManager.object_type, TypeManager.intptr_type });

            TypeManager.RegisterMethod(ConstructorBuilder, const_parameters);
            member_cache.AddMember(ConstructorBuilder, this);

            ConstructorBuilder.SetImplementationFlags(MethodImplAttributes.Runtime);

            //
            // Here the various methods like Invoke, BeginInvoke etc are defined
            //
            // First, call the `out of band' special method for
            // defining recursively any types we need:

            if (!Parameters.Resolve(this))
            {
                return(false);
            }

            //
            // Invoke method
            //

            // Check accessibility
            foreach (Type partype in Parameters.Types)
            {
                if (!IsAccessibleAs(partype))
                {
                    Report.SymbolRelatedToPreviousError(partype);
                    Report.Error(59, Location,
                                 "Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'",
                                 TypeManager.CSharpName(partype),
                                 GetSignatureForError());
                    return(false);
                }
            }

            ReturnType = ReturnType.ResolveAsTypeTerminal(this, false);
            if (ReturnType == null)
            {
                return(false);
            }

            ret_type = ReturnType.Type;

            if (!IsAccessibleAs(ret_type))
            {
                Report.SymbolRelatedToPreviousError(ret_type);
                Report.Error(58, Location,
                             "Inconsistent accessibility: return type `" +
                             TypeManager.CSharpName(ret_type) + "' is less " +
                             "accessible than delegate `" + GetSignatureForError() + "'");
                return(false);
            }

            CheckProtectedModifier();

            if (RootContext.StdLib && TypeManager.IsSpecialType(ret_type))
            {
                Method.Error1599(Location, ret_type, Report);
                return(false);
            }

            TypeManager.CheckTypeVariance(ret_type, Variance.Covariant, this);

            //
            // We don't have to check any others because they are all
            // guaranteed to be accessible - they are standard types.
            //

            CallingConventions cc = Parameters.CallingConvention;

            InvokeBuilder = TypeBuilder.DefineMethod("Invoke",
                                                     mattr,
                                                     cc,
                                                     ret_type,
                                                     Parameters.GetEmitTypes());

            InvokeBuilder.SetImplementationFlags(MethodImplAttributes.Runtime);

            TypeManager.RegisterMethod(InvokeBuilder, Parameters);
            member_cache.AddMember(InvokeBuilder, this);

            //
            // Don't emit async method for compiler generated delegates (e.g. dynamic site containers)
            //
            if (TypeManager.iasyncresult_type != null && TypeManager.asynccallback_type != null && !IsCompilerGenerated)
            {
                DefineAsyncMethods(cc);
            }

            return(true);
        }