Meth() public method

public Meth ( ) : MethodSymbol
return MethodSymbol
Example #1
0
        private void ReportBogus(SymWithType swt)
        {
            Debug.Assert(swt.Sym.hasBogus() && swt.Sym.checkBogus());

            switch (swt.Sym.getKind())
            {
            case SYMKIND.SK_EventSymbol:
                break;

            case SYMKIND.SK_PropertySymbol:
                if (swt.Prop().useMethInstead)
                {
                    MethodSymbol meth1 = swt.Prop().methGet;
                    MethodSymbol meth2 = swt.Prop().methSet;
                    ReportBogusForEventsAndProperties(swt, meth1, meth2);
                    return;
                }
                break;

            case SYMKIND.SK_MethodSymbol:
                if (swt.Meth().name == NameManager.GetPredefinedName(PredefinedName.PN_INVOKE) && swt.Meth().getClass().IsDelegate())
                {
                    swt.Set(swt.Meth().getClass(), swt.GetType());
                }
                break;

            default:
                break;
            }

            // Generic bogus error.
            GetErrorContext().ErrorRef(ErrorCode.ERR_BindToBogus, swt);
        }
Example #2
0
        private EXPR AdjustMemberObject(SymWithType swt, EXPR pObject, out bool pfConstrained, out bool pIsMatchingStatic)
        {
            // Assert that the type is present and is an instantiation of the member's parent.
            Debug.Assert(swt.GetType() != null && swt.GetType().getAggregate() == swt.Sym.parent.AsAggregateSymbol());
            bool bIsMatchingStatic = IsMatchingStatic(swt, pObject);
            pIsMatchingStatic = bIsMatchingStatic;
            pfConstrained = false;

            bool isStatic = swt.Sym.isStatic;

            // If our static doesn't match, bail out of here.
            if (!bIsMatchingStatic)
            {
                if (isStatic)
                {
                    // If we have a mismatched static, a static method, and the binding flag
                    // that tells us we're binding simple names, then insert a type here instead.
                    if ((pObject.flags & EXPRFLAG.EXF_SIMPLENAME) != 0)
                    {
                        // We've made the static match now.
                        pIsMatchingStatic = true;
                        return null;
                    }
                    else
                    {
                        ErrorContext.ErrorRef(ErrorCode.ERR_ObjectProhibited, swt);
                        return null;
                    }
                }
                else
                {
                    ErrorContext.ErrorRef(ErrorCode.ERR_ObjectRequired, swt);
                    return pObject;
                }
            }

            // At this point, all errors for static invocations have been reported, and
            // the object has been nulled out. So return out of here.
            if (isStatic)
            {
                return null;
            }

            // If we're in a constructor, then bail.
            if (swt.Sym.IsMethodSymbol() && swt.Meth().IsConstructor())
            {
                return pObject;
            }

            if (pObject == null)
            {
                if (InFieldInitializer() && !InStaticMethod() && ContainingAgg() == swt.Sym.parent)
                {
                    ErrorContext.ErrorRef(ErrorCode.ERR_FieldInitRefNonstatic, swt); // give better error message for common mistake <BUGNUM>See VS7:119218</BUGNUM>
                }
                else if (InAnonymousMethod() && !InStaticMethod() && ContainingAgg() == swt.Sym.parent && ContainingAgg().IsStruct())
                {
                    ErrorContext.Error(ErrorCode.ERR_ThisStructNotInAnonMeth);
                }
                else
                {
                    return null;
                }

                // For fields or structs, make a this pointer for us to use.

                EXPRTHISPOINTER thisExpr = GetExprFactory().CreateThis(Context.GetThisPointer(), true);
                thisExpr.SetMismatchedStaticBit();
                if (thisExpr.type == null)
                {
                    thisExpr.setType(GetTypes().GetErrorSym());
                }
                return thisExpr;
            }

            CType typeObj = pObject.type;
            CType typeTmp;

            if (typeObj.IsNullableType() && (typeTmp = typeObj.AsNullableType().GetAts(GetErrorContext())) != null && typeTmp != swt.GetType())
            {
                typeObj = typeTmp;
            }

            if (typeObj.IsTypeParameterType() || typeObj.IsAggregateType())
            {
                AggregateSymbol aggCalled = null;
                aggCalled = swt.Sym.parent.AsAggregateSymbol();
                Debug.Assert(swt.GetType().getAggregate() == aggCalled);

                // If we're invoking code on a struct-valued field, mark the struct as assigned (to
                // avoid warning CS0649).
                if (pObject.isFIELD() && !pObject.asFIELD().fwt.Field().isAssigned && !swt.Sym.IsFieldSymbol() &&
                    typeObj.isStructType() && !typeObj.isPredefined())
                {
                    pObject.asFIELD().fwt.Field().isAssigned = true;
                }

                if (pfConstrained &&
                    (typeObj.IsTypeParameterType() ||
                     typeObj.isStructType() && swt.GetType().IsRefType() && swt.Sym.IsVirtual()))
                {
                    // For calls on type parameters or virtual calls on struct types (not enums),
                    // use the constrained prefix.
                    pfConstrained = true;
                }

                EXPR objNew = tryConvert(pObject, swt.GetType(), CONVERTTYPE.NOUDC);

                // This check ensures that we do not bind to methods in an outer class
                // which are visible, but whose this pointer is of an incorrect type...
                // ... also handles case of calling an pObject method on a RefAny value.
                // WE don't give a great message for this, but it'll do.
                if (objNew == null)
                {
                    if (!pObject.type.isSpecialByRefType())
                    {
                        ErrorContext.Error(ErrorCode.ERR_WrongNestedThis, swt.GetType(), pObject.type);
                    }
                    else
                    {
                        ErrorContext.Error(ErrorCode.ERR_NoImplicitConv, pObject.type, swt.GetType());
                    }
                }
                pObject = objNew;
            }

            return pObject;
        }
Example #3
0
        private void ReportBogus(SymWithType swt)
        {
            Debug.Assert(swt.Sym.hasBogus() && swt.Sym.checkBogus());

            switch (swt.Sym.getKind())
            {
                case SYMKIND.SK_EventSymbol:
                    break;

                case SYMKIND.SK_PropertySymbol:
                    if (swt.Prop().useMethInstead)
                    {
                        MethodSymbol meth1 = swt.Prop().methGet;
                        MethodSymbol meth2 = swt.Prop().methSet;
                        ReportBogusForEventsAndProperties(swt, meth1, meth2);
                        return;
                    }
                    break;

                case SYMKIND.SK_MethodSymbol:
                    if (swt.Meth().name == GetSymbolLoader().GetNameManager().GetPredefName(PredefinedName.PN_INVOKE) && swt.Meth().getClass().IsDelegate())
                    {
                        swt.Set(swt.Meth().getClass(), swt.GetType());
                    }
                    break;

                default:
                    break;
            }

            // Generic bogus error.
            GetErrorContext().ErrorRef(ErrorCode.ERR_BindToBogus, swt);
        }