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

changeset 2002
fb5a846c4a49
parent 2000
4a6acc42c3a1
child 2004
438547d895dc
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Sep 02 22:44:06 2013 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Sep 03 23:31:33 2013 +0100
     1.3 @@ -2319,30 +2319,37 @@
     1.4          boolean needsRecovery =
     1.5                  resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK;
     1.6          try {
     1.7 -            Type target = pt();
     1.8 +            Type currentTarget = pt();
     1.9              List<Type> explicitParamTypes = null;
    1.10              if (that.paramKind == JCLambda.ParameterKind.EXPLICIT) {
    1.11                  //attribute lambda parameters
    1.12                  attribStats(that.params, localEnv);
    1.13                  explicitParamTypes = TreeInfo.types(that.params);
    1.14 -                target = infer.instantiateFunctionalInterface(that, target, explicitParamTypes, resultInfo.checkContext);
    1.15              }
    1.16  
    1.17              Type lambdaType;
    1.18              if (pt() != Type.recoveryType) {
    1.19 -                target = targetChecker.visit(target, that);
    1.20 -                lambdaType = types.findDescriptorType(target);
    1.21 +                /* We need to adjust the target. If the target is an
    1.22 +                 * intersection type, for example: SAM & I1 & I2 ...
    1.23 +                 * the target will be updated to SAM
    1.24 +                 */
    1.25 +                currentTarget = targetChecker.visit(currentTarget, that);
    1.26 +                if (explicitParamTypes != null) {
    1.27 +                    currentTarget = infer.instantiateFunctionalInterface(that,
    1.28 +                            currentTarget, explicitParamTypes, resultInfo.checkContext);
    1.29 +                }
    1.30 +                lambdaType = types.findDescriptorType(currentTarget);
    1.31              } else {
    1.32 -                target = Type.recoveryType;
    1.33 +                currentTarget = Type.recoveryType;
    1.34                  lambdaType = fallbackDescriptorType(that);
    1.35              }
    1.36  
    1.37 -            setFunctionalInfo(localEnv, that, pt(), lambdaType, target, resultInfo.checkContext);
    1.38 +            setFunctionalInfo(localEnv, that, pt(), lambdaType, currentTarget, resultInfo.checkContext);
    1.39  
    1.40              if (lambdaType.hasTag(FORALL)) {
    1.41                  //lambda expression target desc cannot be a generic method
    1.42                  resultInfo.checkContext.report(that, diags.fragment("invalid.generic.lambda.target",
    1.43 -                        lambdaType, kindName(target.tsym), target.tsym));
    1.44 +                        lambdaType, kindName(currentTarget.tsym), currentTarget.tsym));
    1.45                  result = that.type = types.createErrorType(pt());
    1.46                  return;
    1.47              }
    1.48 @@ -2376,7 +2383,7 @@
    1.49  
    1.50                  if (arityMismatch) {
    1.51                      resultInfo.checkContext.report(that, diags.fragment("incompatible.arg.types.in.lambda"));
    1.52 -                        result = that.type = types.createErrorType(target);
    1.53 +                        result = that.type = types.createErrorType(currentTarget);
    1.54                          return;
    1.55                  }
    1.56              }
    1.57 @@ -2403,7 +2410,7 @@
    1.58                  attribStats(body.stats, localEnv);
    1.59              }
    1.60  
    1.61 -            result = check(that, target, VAL, resultInfo);
    1.62 +            result = check(that, currentTarget, VAL, resultInfo);
    1.63  
    1.64              boolean isSpeculativeRound =
    1.65                      resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE;
    1.66 @@ -2414,9 +2421,9 @@
    1.67              checkLambdaCompatible(that, lambdaType, resultInfo.checkContext, isSpeculativeRound);
    1.68  
    1.69              if (!isSpeculativeRound) {
    1.70 -                checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType, target);
    1.71 +                checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), lambdaType, currentTarget);
    1.72              }
    1.73 -            result = check(that, target, VAL, resultInfo);
    1.74 +            result = check(that, currentTarget, VAL, resultInfo);
    1.75          } catch (Types.FunctionDescriptorLookupError ex) {
    1.76              JCDiagnostic cause = ex.getDiagnostic();
    1.77              resultInfo.checkContext.report(that, cause);

mercurial