Mono.CSharp.ConstructorInitializer.DoResolve C# (CSharp) Method

DoResolve() protected method

protected DoResolve ( ResolveContext ec ) : Mono.CSharp.Expression
ec ResolveContext
return Mono.CSharp.Expression
        protected override Expression DoResolve(ResolveContext ec)
        {
            eclass = ExprClass.Value;

            // FIXME: Hack
            var caller_builder = (Constructor) ec.MemberContext;

            //
            // Spec mandates that constructor initializer will not have `this' access
            //
            using (ec.Set (ResolveContext.Options.BaseInitializer)) {
                if (argument_list != null) {
                    bool dynamic;
                    argument_list.Resolve (ec, out dynamic);

                    if (dynamic) {
                        ec.Report.Error (1975, loc,
                            "The constructor call cannot be dynamically dispatched within constructor initializer");

                        return null;
                    }
                }

                type = ec.CurrentType;
                if (this is ConstructorBaseInitializer) {
                    if (ec.CurrentType.BaseType == null)
                        return this;

                    type = ec.CurrentType.BaseType;
                    if (ec.CurrentType.IsStruct) {
                        ec.Report.Error (522, loc,
                            "`{0}': Struct constructors cannot call base constructors", caller_builder.GetSignatureForError ());
                        return this;
                    }
                } else {
                    //
                    // It is legal to have "this" initializers that take no arguments
                    // in structs, they are just no-ops.
                    //
                    // struct D { public D (int a) : this () {}
                    //
                    if (TypeManager.IsStruct (ec.CurrentType) && argument_list == null)
                        return this;
                }

                base_ctor = ConstructorLookup (ec, type, ref argument_list, loc);
            }

            // TODO MemberCache: Does it work for inflated types ?
            if (base_ctor == caller_builder.Spec){
                ec.Report.Error (516, loc, "Constructor `{0}' cannot call itself",
                    caller_builder.GetSignatureForError ());
            }

            return this;
        }