langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java
changeset 29554 6d7957bd6866
parent 29147 4cba0458106b
child 29555 71f15ff4b409
equal deleted inserted replaced
29553:716d47f5a45e 29554:6d7957bd6866
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package com.sun.tools.javac.comp;
    26 package com.sun.tools.javac.comp;
    27 
    27 
       
    28 import com.sun.tools.javac.code.Type.TypeMapping;
    28 import com.sun.tools.javac.tree.JCTree;
    29 import com.sun.tools.javac.tree.JCTree;
    29 import com.sun.tools.javac.tree.JCTree.JCTypeCast;
    30 import com.sun.tools.javac.tree.JCTree.JCTypeCast;
    30 import com.sun.tools.javac.tree.TreeInfo;
    31 import com.sun.tools.javac.tree.TreeInfo;
    31 import com.sun.tools.javac.util.*;
    32 import com.sun.tools.javac.util.*;
    32 import com.sun.tools.javac.util.GraphUtils.DottableNode;
    33 import com.sun.tools.javac.util.GraphUtils.DottableNode;
   475                 break;
   476                 break;
   476             default:
   477             default:
   477                 restype = syms.objectType;
   478                 restype = syms.objectType;
   478         }
   479         }
   479 
   480 
   480         List<Type> paramtypes = Type.map(argtypes, new ImplicitArgType(spMethod, resolveContext.step));
   481         List<Type> paramtypes = argtypes.map(new ImplicitArgType(spMethod, resolveContext.step));
   481         List<Type> exType = spMethod != null ?
   482         List<Type> exType = spMethod != null ?
   482             spMethod.getThrownTypes() :
   483             spMethod.getThrownTypes() :
   483             List.of(syms.throwableType); // make it throw all exceptions
   484             List.of(syms.throwableType); // make it throw all exceptions
   484 
   485 
   485         MethodType mtype = new MethodType(paramtypes,
   486         MethodType mtype = new MethodType(paramtypes,
   493 
   494 
   494             public ImplicitArgType(Symbol msym, Resolve.MethodResolutionPhase phase) {
   495             public ImplicitArgType(Symbol msym, Resolve.MethodResolutionPhase phase) {
   495                 (rs.deferredAttr).super(AttrMode.SPECULATIVE, msym, phase);
   496                 (rs.deferredAttr).super(AttrMode.SPECULATIVE, msym, phase);
   496             }
   497             }
   497 
   498 
   498             public Type apply(Type t) {
   499             @Override
   499                 t = types.erasure(super.apply(t));
   500             public Type visitClassType(ClassType t, Void aVoid) {
   500                 if (t.hasTag(BOT))
   501                 return types.erasure(t);
       
   502             }
       
   503 
       
   504             @Override
       
   505             public Type visitType(Type t, Void _unused) {
       
   506                 if (t.hasTag(DEFERRED)) {
       
   507                     return visit(super.visitType(t, null));
       
   508                 } else if (t.hasTag(BOT))
   501                     // nulls type as the marker type Null (which has no instances)
   509                     // nulls type as the marker type Null (which has no instances)
   502                     // infer as java.lang.Void for now
   510                     // infer as java.lang.Void for now
   503                     t = types.boxedClass(syms.voidType).type;
   511                     t = types.boxedClass(syms.voidType).type;
   504                 return t;
   512                 return t;
   505             }
   513             }
  2044         Map<FreeTypeListener, List<Type>> freeTypeListeners = new HashMap<>();
  2052         Map<FreeTypeListener, List<Type>> freeTypeListeners = new HashMap<>();
  2045 
  2053 
  2046         List<FreeTypeListener> freetypeListeners = List.nil();
  2054         List<FreeTypeListener> freetypeListeners = List.nil();
  2047 
  2055 
  2048         public InferenceContext(List<Type> inferencevars) {
  2056         public InferenceContext(List<Type> inferencevars) {
  2049             this.undetvars = Type.map(inferencevars, fromTypeVarFun);
  2057             this.undetvars = inferencevars.map(fromTypeVarFun);
  2050             this.inferencevars = inferencevars;
  2058             this.inferencevars = inferencevars;
  2051         }
  2059         }
  2052         //where
  2060         //where
  2053             Mapping fromTypeVarFun = new Mapping("fromTypeVarFunWithBounds") {
  2061             TypeMapping<Void> fromTypeVarFun = new TypeMapping<Void>() {
  2054                 // mapping that turns inference variables into undet vars
  2062                 @Override
  2055                 public Type apply(Type t) {
  2063                 public Type visitTypeVar(TypeVar tv, Void aVoid) {
  2056                     if (t.hasTag(TYPEVAR)) {
  2064                     return new UndetVar(tv, types);
  2057                         TypeVar tv = (TypeVar)t;
  2065                 }
  2058                         if (tv.isCaptured()) {
  2066 
  2059                             return new CapturedUndetVar((CapturedType)tv, types);
  2067                 @Override
  2060                         } else {
  2068                 public Type visitCapturedType(CapturedType t, Void aVoid) {
  2061                             return new UndetVar(tv, types);
  2069                     return new CapturedUndetVar(t, types);
  2062                         }
       
  2063                     } else {
       
  2064                         return t.map(this);
       
  2065                     }
       
  2066                 }
  2070                 }
  2067             };
  2071             };
  2068 
  2072 
  2069         /**
  2073         /**
  2070          * add a new inference var to this inference context
  2074          * add a new inference var to this inference context