private void instantiateAsUninferredVars ( List < Type > vars , InferenceContext inferenceContext ) { ListBuffer < Type > todo = new ListBuffer <> ( ) ; //step 1 - create fresh tvars for ( Type t : vars ) { UndetVar uv = ( UndetVar ) inferenceContext . asUndetVar ( t ) ; List < Type > upperBounds = uv . getBounds ( InferenceBound . UPPER ) ; if ( Type . containsAny ( upperBounds , vars ) ) { TypeSymbol fresh_tvar = new TypeVariableSymbol ( Flags . SYNTHETIC , uv . qtype . tsym . name , null , uv . qtype . tsym . owner ) ; fresh_tvar . type = new TypeVar ( fresh_tvar , types . makeIntersectionType ( uv . getBounds ( InferenceBound . UPPER ) ) , null ) ; todo . append ( uv ) ; uv . inst = fresh_tvar . type ; } else if ( upperBounds . nonEmpty ( ) ) { uv . inst = types . glb ( upperBounds ) ; } else { uv . inst = syms . objectType ; } } //step 2 - replace fresh tvars in their bounds List < Type > formals = vars ; for ( Type t : todo ) { UndetVar uv = ( UndetVar ) t ; TypeVar ct = ( TypeVar ) uv . inst ; ct . bound = types . glb ( inferenceContext . asInstTypes ( types . getBounds ( ct ) ) ) ; if ( ct . bound . isErroneous ( ) ) { //report inference error if glb fails reportBoundError ( uv , BoundErrorKind . BAD_UPPER ) ; } formals = formals . tail ; } }
Infer cyclic inference variables as described in 15 . 12 . 2 . 8 .