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

changeset 2019
77d395862700
parent 2004
438547d895dc
child 2028
4ce8148ffc4f
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Sep 09 17:36:23 2013 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Sep 09 23:13:45 2013 +0200
     1.3 @@ -2418,9 +2418,17 @@
     1.4              preFlow(that);
     1.5              flow.analyzeLambda(env, that, make, isSpeculativeRound);
     1.6  
     1.7 -            checkLambdaCompatible(that, lambdaType, resultInfo.checkContext, isSpeculativeRound);
     1.8 +            checkLambdaCompatible(that, lambdaType, resultInfo.checkContext);
     1.9  
    1.10              if (!isSpeculativeRound) {
    1.11 +                //add thrown types as bounds to the thrown types free variables if needed:
    1.12 +                if (resultInfo.checkContext.inferenceContext().free(lambdaType.getThrownTypes())) {
    1.13 +                    List<Type> inferredThrownTypes = flow.analyzeLambdaThrownTypes(env, that, make);
    1.14 +                    List<Type> thrownTypes = resultInfo.checkContext.inferenceContext().asFree(lambdaType.getThrownTypes());
    1.15 +
    1.16 +                    chk.unhandled(inferredThrownTypes, thrownTypes);
    1.17 +                }
    1.18 +
    1.19                  checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType, currentTarget);
    1.20              }
    1.21              result = check(that, currentTarget, VAL, resultInfo);
    1.22 @@ -2587,10 +2595,9 @@
    1.23          * Lambda compatibility. Check that given return types, thrown types, parameter types
    1.24          * are compatible with the expected functional interface descriptor. This means that:
    1.25          * (i) parameter types must be identical to those of the target descriptor; (ii) return
    1.26 -        * types must be compatible with the return type of the expected descriptor;
    1.27 -        * (iii) finish inference of thrown types if required.
    1.28 +        * types must be compatible with the return type of the expected descriptor.
    1.29          */
    1.30 -        private void checkLambdaCompatible(JCLambda tree, Type descriptor, CheckContext checkContext, boolean speculativeAttr) {
    1.31 +        private void checkLambdaCompatible(JCLambda tree, Type descriptor, CheckContext checkContext) {
    1.32              Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType());
    1.33  
    1.34              //return values have already been checked - but if lambda has no return
    1.35 @@ -2607,11 +2614,6 @@
    1.36              if (!types.isSameTypes(argTypes, TreeInfo.types(tree.params))) {
    1.37                  checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda"));
    1.38              }
    1.39 -
    1.40 -            if (!speculativeAttr) {
    1.41 -                List<Type> thrownTypes = checkContext.inferenceContext().asFree(descriptor.getThrownTypes());
    1.42 -                chk.unhandled(tree.inferredThrownTypes == null ? List.<Type>nil() : tree.inferredThrownTypes, thrownTypes);
    1.43 -            }
    1.44          }
    1.45  
    1.46          private Env<AttrContext> lambdaEnv(JCLambda that, Env<AttrContext> env) {

mercurial