langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java
changeset 45504 ea7475564d07
parent 45498 0848a6cbe2a3
child 45754 740593904730
equal deleted inserted replaced
45503:d23ae2d67a5d 45504:ea7475564d07
    26 package com.sun.tools.javac.comp;
    26 package com.sun.tools.javac.comp;
    27 
    27 
    28 import com.sun.tools.javac.code.Type.UndetVar.UndetVarListener;
    28 import com.sun.tools.javac.code.Type.UndetVar.UndetVarListener;
    29 import com.sun.tools.javac.code.Types.TypeMapping;
    29 import com.sun.tools.javac.code.Types.TypeMapping;
    30 import com.sun.tools.javac.comp.Attr.CheckMode;
    30 import com.sun.tools.javac.comp.Attr.CheckMode;
       
    31 import com.sun.tools.javac.resources.CompilerProperties.Fragments;
       
    32 import com.sun.tools.javac.resources.CompilerProperties.Notes;
    31 import com.sun.tools.javac.tree.JCTree;
    33 import com.sun.tools.javac.tree.JCTree;
    32 import com.sun.tools.javac.tree.JCTree.JCTypeCast;
    34 import com.sun.tools.javac.tree.JCTree.JCTypeCast;
    33 import com.sun.tools.javac.tree.TreeInfo;
    35 import com.sun.tools.javac.tree.TreeInfo;
    34 import com.sun.tools.javac.util.*;
    36 import com.sun.tools.javac.util.*;
    35 import com.sun.tools.javac.util.GraphUtils.DottableNode;
    37 import com.sun.tools.javac.util.GraphUtils.DottableNode;
   236                 inferenceContext.solveLegacy(false, warn, LegacyInferenceSteps.EQ_UPPER.steps); //maximizeInst
   238                 inferenceContext.solveLegacy(false, warn, LegacyInferenceSteps.EQ_UPPER.steps); //maximizeInst
   237                 mt = (MethodType)inferenceContext.asInstType(mt);
   239                 mt = (MethodType)inferenceContext.asInstType(mt);
   238             }
   240             }
   239 
   241 
   240             if (resultInfo != null && rs.verboseResolutionMode.contains(VerboseResolutionMode.DEFERRED_INST)) {
   242             if (resultInfo != null && rs.verboseResolutionMode.contains(VerboseResolutionMode.DEFERRED_INST)) {
   241                 log.note(env.tree.pos, "deferred.method.inst", msym, mt, resultInfo.pt);
   243                 log.note(env.tree.pos, Notes.DeferredMethodInst(msym, mt, resultInfo.pt));
   242             }
   244             }
   243 
   245 
   244             // return instantiated version of method type
   246             // return instantiated version of method type
   245             return mt;
   247             return mt;
   246         } finally {
   248         } finally {
   663             //get constraints from explicit params (this is done by
   665             //get constraints from explicit params (this is done by
   664             //checking that explicit param types are equal to the ones
   666             //checking that explicit param types are equal to the ones
   665             //in the functional interface descriptors)
   667             //in the functional interface descriptors)
   666             List<Type> descParameterTypes = types.findDescriptorType(formalInterface).getParameterTypes();
   668             List<Type> descParameterTypes = types.findDescriptorType(formalInterface).getParameterTypes();
   667             if (descParameterTypes.size() != paramTypes.size()) {
   669             if (descParameterTypes.size() != paramTypes.size()) {
   668                 checkContext.report(pos, diags.fragment("incompatible.arg.types.in.lambda"));
   670                 checkContext.report(pos, diags.fragment(Fragments.IncompatibleArgTypesInLambda));
   669                 return types.createErrorType(funcInterface);
   671                 return types.createErrorType(funcInterface);
   670             }
   672             }
   671             for (Type p : descParameterTypes) {
   673             for (Type p : descParameterTypes) {
   672                 if (!types.isSameType(funcInterfaceContext.asUndetVar(p), paramTypes.head)) {
   674                 if (!types.isSameType(funcInterfaceContext.asUndetVar(p), paramTypes.head)) {
   673                     checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface));
   675                     checkContext.report(pos, diags.fragment(Fragments.NoSuitableFunctionalIntfInst(funcInterface)));
   674                     return types.createErrorType(funcInterface);
   676                     return types.createErrorType(funcInterface);
   675                 }
   677                 }
   676                 paramTypes = paramTypes.tail;
   678                 paramTypes = paramTypes.tail;
   677             }
   679             }
   678 
   680 
   687 
   689 
   688             Type owntype = funcInterfaceContext.asInstType(formalInterface);
   690             Type owntype = funcInterfaceContext.asInstType(formalInterface);
   689             if (!chk.checkValidGenericType(owntype)) {
   691             if (!chk.checkValidGenericType(owntype)) {
   690                 //if the inferred functional interface type is not well-formed,
   692                 //if the inferred functional interface type is not well-formed,
   691                 //or if it's not a subtype of the original target, issue an error
   693                 //or if it's not a subtype of the original target, issue an error
   692                 checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface));
   694                 checkContext.report(pos, diags.fragment(Fragments.NoSuitableFunctionalIntfInst(funcInterface)));
   693             }
   695             }
   694             //propagate constraints as per JLS 18.2.1
   696             //propagate constraints as per JLS 18.2.1
   695             checkContext.compatible(owntype, funcInterface, types.noWarnings);
   697             checkContext.compatible(owntype, funcInterface, types.noWarnings);
   696             return owntype;
   698             return owntype;
   697         }
   699         }