src/share/classes/com/sun/tools/javac/comp/Infer.java

Print this page




 356                 .cachedCapture(tree, from.inst, false);
 357         if (types.isConvertible(capturedType,
 358                 resultInfo.checkContext.inferenceContext().asUndetVar(to))) {
 359             //effectively skip additional return-type constraint generation (compatibility)
 360             return syms.objectType;
 361         }
 362         return to;
 363     }
 364 
 365     /**
 366       * Infer cyclic inference variables as described in 15.12.2.8.
 367       */
 368     private void instantiateAsUninferredVars(List<Type> vars, InferenceContext inferenceContext) {
 369         ListBuffer<Type> todo = new ListBuffer<>();
 370         //step 1 - create fresh tvars
 371         for (Type t : vars) {
 372             UndetVar uv = (UndetVar)inferenceContext.asUndetVar(t);
 373             List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER);
 374             if (Type.containsAny(upperBounds, vars)) {
 375                 TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner);
 376                 fresh_tvar.type = new TypeVar(fresh_tvar, types.makeCompoundType(uv.getBounds(InferenceBound.UPPER)), null);
 377                 todo.append(uv);
 378                 uv.inst = fresh_tvar.type;
 379             } else if (upperBounds.nonEmpty()) {
 380                 uv.inst = types.glb(upperBounds);
 381             } else {
 382                 uv.inst = syms.objectType;
 383             }
 384         }
 385         //step 2 - replace fresh tvars in their bounds
 386         List<Type> formals = vars;
 387         for (Type t : todo) {
 388             UndetVar uv = (UndetVar)t;
 389             TypeVar ct = (TypeVar)uv.inst;
 390             ct.bound = types.glb(inferenceContext.asInstTypes(types.getBounds(ct)));
 391             if (ct.bound.isErroneous()) {
 392                 //report inference error if glb fails
 393                 reportBoundError(uv, BoundErrorKind.BAD_UPPER);
 394             }
 395             formals = formals.tail;
 396         }




 356                 .cachedCapture(tree, from.inst, false);
 357         if (types.isConvertible(capturedType,
 358                 resultInfo.checkContext.inferenceContext().asUndetVar(to))) {
 359             //effectively skip additional return-type constraint generation (compatibility)
 360             return syms.objectType;
 361         }
 362         return to;
 363     }
 364 
 365     /**
 366       * Infer cyclic inference variables as described in 15.12.2.8.
 367       */
 368     private void instantiateAsUninferredVars(List<Type> vars, InferenceContext inferenceContext) {
 369         ListBuffer<Type> todo = new ListBuffer<>();
 370         //step 1 - create fresh tvars
 371         for (Type t : vars) {
 372             UndetVar uv = (UndetVar)inferenceContext.asUndetVar(t);
 373             List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER);
 374             if (Type.containsAny(upperBounds, vars)) {
 375                 TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner);
 376                 fresh_tvar.type = new TypeVar(fresh_tvar, types.makeIntersectionType(uv.getBounds(InferenceBound.UPPER)), null);
 377                 todo.append(uv);
 378                 uv.inst = fresh_tvar.type;
 379             } else if (upperBounds.nonEmpty()) {
 380                 uv.inst = types.glb(upperBounds);
 381             } else {
 382                 uv.inst = syms.objectType;
 383             }
 384         }
 385         //step 2 - replace fresh tvars in their bounds
 386         List<Type> formals = vars;
 387         for (Type t : todo) {
 388             UndetVar uv = (UndetVar)t;
 389             TypeVar ct = (TypeVar)uv.inst;
 390             ct.bound = types.glb(inferenceContext.asInstTypes(types.getBounds(ct)));
 391             if (ct.bound.isErroneous()) {
 392                 //report inference error if glb fails
 393                 reportBoundError(uv, BoundErrorKind.BAD_UPPER);
 394             }
 395             formals = formals.tail;
 396         }