Exemplo n.º 1
0
            private void ReportErrorsOnFailure()
            {
                // First and foremost, report if the user specified a name more than once.
                if (_pDuplicateSpecifiedName != null)
                {
                    GetErrorContext().Error(ErrorCode.ERR_DuplicateNamedArgument, _pDuplicateSpecifiedName);
                    return;
                }

                Debug.Assert(_methList.IsEmpty());
                // Report inaccessible.
                if (_results.GetInaccessibleResult())
                {
                    // We might have called this, but it is inaccesable...
                    GetSemanticChecker().ReportAccessError(_results.GetInaccessibleResult(), _pExprBinder.ContextForMemberLookup(), GetTypeQualifier(_pGroup));
                    return;
                }

                // Report bogus.
                if (_mpwiBogus)
                {
                    // We might have called this, but it is bogus...
                    GetErrorContext().ErrorRef(ErrorCode.ERR_BindToBogus, _mpwiBogus);
                    return;
                }

                bool bUseDelegateErrors = false;
                Name nameErr = _pGroup.name;

                // Check for an invoke.
                if (_pGroup.GetOptionalObject() != null &&
                        _pGroup.GetOptionalObject().type != null &&
                        _pGroup.GetOptionalObject().type.isDelegateType() &&
                        _pGroup.name == GetSymbolLoader().GetNameManager().GetPredefName(PredefinedName.PN_INVOKE))
                {
                    Debug.Assert(!_results.GetBestResult() || _results.GetBestResult().MethProp().getClass().IsDelegate());
                    Debug.Assert(!_results.GetBestResult() || _results.GetBestResult().GetType().getAggregate().IsDelegate());
                    bUseDelegateErrors = true;
                    nameErr = _pGroup.GetOptionalObject().type.getAggregate().name;
                }

                if (_results.GetBestResult())
                {
                    // If we had some invalid arguments for best matching.
                    ReportErrorsForBestMatching(bUseDelegateErrors, nameErr);
                }
                else if (_results.GetUninferrableResult() || _mpwiCantInferInstArg)
                {
                    if (!_results.GetUninferrableResult())
                    {
                        //copy the extension method for which instacne argument type inference failed
                        _results.GetUninferrableResult().Set(_mpwiCantInferInstArg.Sym.AsMethodSymbol(), _mpwiCantInferInstArg.GetType(), _mpwiCantInferInstArg.TypeArgs);
                    }
                    Debug.Assert(_results.GetUninferrableResult().Sym.IsMethodSymbol());

                    MethodSymbol sym = _results.GetUninferrableResult().Meth();
                    TypeArray pCurrentParameters = sym.Params;
                    // if we tried to bind to an extensionmethod and the instance argument Type Inference failed then the method does not exist
                    // on the type at all. this is treated as a lookup error
                    CType type = null;
                    if (_pGroup.GetOptionalObject() != null)
                    {
                        type = _pGroup.GetOptionalObject().type;
                    }
                    else if (_pGroup.GetOptionalLHS() != null)
                    {
                        type = _pGroup.GetOptionalLHS().type;
                    }

                    MethWithType mwtCantInfer = new MethWithType();
                    mwtCantInfer.Set(_results.GetUninferrableResult().Meth(), _results.GetUninferrableResult().GetType());
                    GetErrorContext().Error(ErrorCode.ERR_CantInferMethTypeArgs, mwtCantInfer);
                }
                else if (_mwtBadArity)
                {
                    int cvar = _mwtBadArity.Meth().typeVars.size;
                    GetErrorContext().ErrorRef(cvar > 0 ? ErrorCode.ERR_BadArity : ErrorCode.ERR_HasNoTypeVars, _mwtBadArity, new ErrArgSymKind(_mwtBadArity.Meth()), _pArguments.carg);
                }
                else if (_mpwiParamTypeConstraints)
                {
                    // This will always report an error
                    TypeBind.CheckMethConstraints(GetSemanticChecker(), GetErrorContext(), new MethWithInst(_mpwiParamTypeConstraints));
                }
                else if (_pInvalidSpecifiedName != null)
                {
                    // Give a better message for delegate invoke.
                    if (_pGroup.GetOptionalObject() != null &&
                            _pGroup.GetOptionalObject().type.IsAggregateType() &&
                            _pGroup.GetOptionalObject().type.AsAggregateType().GetOwningAggregate().IsDelegate())
                    {
                        GetErrorContext().Error(ErrorCode.ERR_BadNamedArgumentForDelegateInvoke, _pGroup.GetOptionalObject().type.AsAggregateType().GetOwningAggregate().name, _pInvalidSpecifiedName);
                    }
                    else
                    {
                        GetErrorContext().Error(ErrorCode.ERR_BadNamedArgument, _pGroup.name, _pInvalidSpecifiedName);
                    }
                }
                else if (_pNameUsedInPositionalArgument != null)
                {
                    GetErrorContext().Error(ErrorCode.ERR_NamedArgumentUsedInPositional, _pNameUsedInPositionalArgument);
                }
                else
                {
                    CParameterizedError error;

                    if (_pDelegate != null)
                    {
                        GetErrorContext().MakeError(out error, ErrorCode.ERR_MethDelegateMismatch, nameErr, _pDelegate);
                        GetErrorContext().AddRelatedTypeLoc(error, _pDelegate);
                    }
                    else
                    {
                        // The number of arguments must be wrong.

                        if (_fCandidatesUnsupported)
                        {
                            GetErrorContext().MakeError(out error, ErrorCode.ERR_BindToBogus, nameErr);
                        }
                        else if (bUseDelegateErrors)
                        {
                            Debug.Assert(0 == (_pGroup.flags & EXPRFLAG.EXF_CTOR));
                            GetErrorContext().MakeError(out error, ErrorCode.ERR_BadDelArgCount, nameErr, _pArguments.carg);
                        }
                        else
                        {
                            if (0 != (_pGroup.flags & EXPRFLAG.EXF_CTOR))
                            {
                                Debug.Assert(!_pGroup.GetParentType().IsTypeParameterType());
                                GetErrorContext().MakeError(out error, ErrorCode.ERR_BadCtorArgCount, _pGroup.GetParentType(), _pArguments.carg);
                            }
                            else
                            {
                                GetErrorContext().MakeError(out error, ErrorCode.ERR_BadArgCount, nameErr, _pArguments.carg);
                            }
                        }
                    }

                    // Report possible matches (same name and is accesible). We stored these in m_swtWrongCount.
                    for (int i = 0; i < _nWrongCount; i++)
                    {
                        if (GetSemanticChecker().CheckAccess(
                                    _swtWrongCount[i].Sym,
                                    _swtWrongCount[i].GetType(),
                                    _pExprBinder.ContextForMemberLookup(),
                                    GetTypeQualifier(_pGroup)))
                        {
                            GetErrorContext().AddRelatedSymLoc(error, _swtWrongCount[i].Sym);
                        }
                    }
                    GetErrorContext().SubmitError(error);
                }
            }
Exemplo n.º 2
0
        protected void PostBindProperty(bool fBaseCall, PropWithType pwt, EXPR pObject, out MethWithType pmwtGet, out MethWithType pmwtSet)
        {
            pmwtGet = new MethWithType();
            pmwtSet = new MethWithType();
            // Get the accessors.
            if (pwt.Prop().methGet != null)
            {
                pmwtGet.Set(pwt.Prop().methGet, pwt.GetType());
            }
            else
            {
                pmwtGet.Clear();
            }

            if (pwt.Prop().methSet != null)
            {
                pmwtSet.Set(pwt.Prop().methSet, pwt.GetType());
            }
            else
            {
                pmwtSet.Clear();
            }

            // If it is virtual, find a remap of the method to something more specific.  This
            // may alter where the accessors are found.
            if (fBaseCall && pObject != null)
            {
                if (pmwtGet)
                {
                    RemapToOverride(GetSymbolLoader(), pmwtGet, pObject.type);
                }
                if (pmwtSet)
                {
                    RemapToOverride(GetSymbolLoader(), pmwtSet, pObject.type);
                }
            }

            if (pwt.Prop().RetType != null)
            {
                checkUnsafe(pwt.Prop().RetType);
            }
        }