Type instantiateMethod( Env<AttrContext> env,
                            List<Type> tvars,
                            MethodType mt,
                            Attr.ResultInfo resultInfo,
                            MethodSymbol msym,
                            List<Type> argtypes,
                            boolean allowBoxing,
                            boolean useVarargs,
                            Resolve.MethodResolutionContext resolveContext,
                            Warner warn) throws InferenceException {
        //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG
        final InferenceContext inferenceContext = new InferenceContext(this, tvars);  //B0
        inferenceException.clear();
        try {
            DeferredAttr.DeferredAttrContext deferredAttrContext =
                        resolveContext.deferredAttrContext(msym, inferenceContext, resultInfo, warn);

            resolveContext.methodCheck.argumentsAcceptable(env, deferredAttrContext,   //B2
                    argtypes, mt.getParameterTypes(), warn);

            if (allowGraphInference && resultInfo != null && resultInfo.pt == anyPoly) {
                doIncorporation(inferenceContext, warn);
                //we are inside method attribution - just return a partially inferred type
                return new PartiallyInferredMethodType(mt, inferenceContext, env, warn);
            } else if (allowGraphInference && resultInfo != null) {

                //inject return constraints earlier
                doIncorporation(inferenceContext, warn); //propagation

                if (!warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) {
                    boolean shouldPropagate = shouldPropagate(mt.getReturnType(), resultInfo, inferenceContext);

                    InferenceContext minContext = shouldPropagate ?
                            inferenceContext.min(roots(mt, deferredAttrContext), true, warn) :
                            inferenceContext;

                    Type newRestype = generateReturnConstraints(env.tree, resultInfo,  //B3
                            mt, minContext);
                    mt = (MethodType)types.createMethodTypeWithReturn(mt, newRestype);

                    //propagate outwards if needed
                    if (shouldPropagate) {
                        //propagate inference context outwards and exit
                        minContext.dupTo(resultInfo.checkContext.inferenceContext());
                        deferredAttrContext.complete();
                        return mt;
                    }
                }
            }

            deferredAttrContext.complete();

            // minimize as yet undetermined type variables
            if (allowGraphInference) {
                inferenceContext.solve(warn);
            } else {
                inferenceContext.solveLegacy(true, warn, LegacyInferenceSteps.EQ_LOWER.steps); //minimizeInst
            }

            mt = (MethodType)inferenceContext.asInstType(mt);

            if (!allowGraphInference &&
                    inferenceContext.restvars().nonEmpty() &&
                    resultInfo != null &&
                    !warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) {
                generateReturnConstraints(env.tree, resultInfo, mt, inferenceContext);
                inferenceContext.solveLegacy(false, warn, LegacyInferenceSteps.EQ_UPPER.steps); //maximizeInst
                mt = (MethodType)inferenceContext.asInstType(mt);
            }

            if (resultInfo != null && rs.verboseResolutionMode.contains(VerboseResolutionMode.DEFERRED_INST)) {
                log.note(env.tree.pos, "deferred.method.inst", msym, mt, resultInfo.pt);
            }

            // return instantiated version of method type
            return mt;
        } finally {
            if (resultInfo != null || !allowGraphInference) {
                inferenceContext.notifyChange();
            } else {
                inferenceContext.notifyChange(inferenceContext.boundedVars());
            }
            if (resultInfo == null) {
                /* if the is no result info then we can clear the capture types
                 * cache without affecting any result info check
                 */
                inferenceContext.captureTypeCache.clear();
            }
            dumpGraphsIfNeeded(env.tree, msym, resolveContext);
        }
    }
Type instantiateMethod ( Env < AttrContext > env , List < Type > tvars , MethodType mt , Attr . ResultInfo resultInfo , MethodSymbol msym , List < Type > argtypes , boolean allowBoxing , boolean useVarargs , Resolve . MethodResolutionContext resolveContext , Warner warn ) throws InferenceException { final InferenceContext inferenceContext = new InferenceContext ( this , tvars ) ; inferenceException . clear ( ) ; try { DeferredAttr . DeferredAttrContext deferredAttrContext = resolveContext . deferredAttrContext ( msym , inferenceContext , resultInfo , warn ) ; resolveContext . methodCheck . argumentsAcceptable ( env , deferredAttrContext , argtypes , mt . getParameterTypes ( ) , warn ) ; if ( allowGraphInference && resultInfo != null && resultInfo . pt == anyPoly ) { doIncorporation ( inferenceContext , warn ) ; return new PartiallyInferredMethodType ( mt , inferenceContext , env , warn ) ; } else if ( allowGraphInference && resultInfo != null ) { doIncorporation ( inferenceContext , warn ) ; if ( ! warn . hasNonSilentLint ( Lint . LintCategory . UNCHECKED ) ) { boolean shouldPropagate = shouldPropagate ( mt . getReturnType ( ) , resultInfo , inferenceContext ) ; InferenceContext minContext = shouldPropagate ? inferenceContext . min ( roots ( mt , deferredAttrContext ) , true , warn ) : inferenceContext ; Type newRestype = generateReturnConstraints ( env . tree , resultInfo , mt , minContext ) ; mt = ( MethodType ) types . createMethodTypeWithReturn ( mt , newRestype ) ; if ( shouldPropagate ) { minContext . dupTo ( resultInfo . checkContext . inferenceContext ( ) ) ; deferredAttrContext . complete ( ) ; return mt ; } } } deferredAttrContext . complete ( ) ; if ( allowGraphInference ) { inferenceContext . solve ( warn ) ; } else { inferenceContext . solveLegacy ( true , warn , LegacyInferenceSteps . EQ_LOWER . steps ) ; } mt = ( MethodType ) inferenceContext . asInstType ( mt ) ; if ( ! allowGraphInference && inferenceContext . restvars ( ) . nonEmpty ( ) && resultInfo != null && ! warn . hasNonSilentLint ( Lint . LintCategory . UNCHECKED ) ) { generateReturnConstraints ( env . tree , resultInfo , mt , inferenceContext ) ; inferenceContext . solveLegacy ( false , warn , LegacyInferenceSteps . EQ_UPPER . steps ) ; mt = ( MethodType ) inferenceContext . asInstType ( mt ) ; } if ( resultInfo != null && rs . verboseResolutionMode . contains ( VerboseResolutionMode . DEFERRED_INST ) ) { log . note ( env . tree . pos , "deferred.method.inst" , msym , mt , resultInfo . pt ) ; } return mt ; } finally { if ( resultInfo != null || ! allowGraphInference ) { inferenceContext . notifyChange ( ) ; } else { inferenceContext . notifyChange ( inferenceContext . boundedVars ( ) ) ; } if ( resultInfo == null ) { inferenceContext . captureTypeCache . clear ( ) ; } dumpGraphsIfNeeded ( env . tree , msym , resolveContext ) ; } }
Main inference entry point - instantiate a generic method type
using given argument types and (possibly) an expected target-type.