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

changeset 2543
c6d5efccedc3
parent 2428
ce1d9dd2e9eb
child 2558
d560276b8a35
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Jul 17 10:55:50 2014 -0400
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Fri Jun 20 20:36:54 2014 +0100
     1.3 @@ -252,36 +252,30 @@
     1.4       */
     1.5      Type check(final JCTree tree, final Type found, final int ownkind, final ResultInfo resultInfo) {
     1.6          InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext();
     1.7 -        Type owntype = found;
     1.8 -        if (!owntype.hasTag(ERROR) && !resultInfo.pt.hasTag(METHOD) && !resultInfo.pt.hasTag(FORALL)) {
     1.9 -            if (allowPoly && inferenceContext.free(found)) {
    1.10 -                if ((ownkind & ~resultInfo.pkind) == 0) {
    1.11 -                    owntype = resultInfo.check(tree, inferenceContext.asUndetVar(owntype));
    1.12 -                } else {
    1.13 -                    log.error(tree.pos(), "unexpected.type",
    1.14 -                            kindNames(resultInfo.pkind),
    1.15 -                            kindName(ownkind));
    1.16 -                    owntype = types.createErrorType(owntype);
    1.17 -                }
    1.18 +        Type owntype;
    1.19 +        if (!found.hasTag(ERROR) && !resultInfo.pt.hasTag(METHOD) && !resultInfo.pt.hasTag(FORALL)) {
    1.20 +            if ((ownkind & ~resultInfo.pkind) != 0) {
    1.21 +                log.error(tree.pos(), "unexpected.type",
    1.22 +                        kindNames(resultInfo.pkind),
    1.23 +                        kindName(ownkind));
    1.24 +                owntype = types.createErrorType(found);
    1.25 +            } else if (allowPoly && inferenceContext.free(found)) {
    1.26 +                //delay the check if there are inference variables in the found type
    1.27 +                //this means we are dealing with a partially inferred poly expression
    1.28 +                owntype = resultInfo.pt;
    1.29                  inferenceContext.addFreeTypeListener(List.of(found, resultInfo.pt), new FreeTypeListener() {
    1.30                      @Override
    1.31                      public void typesInferred(InferenceContext inferenceContext) {
    1.32                          ResultInfo pendingResult =
    1.33 -                                    resultInfo.dup(inferenceContext.asInstType(resultInfo.pt));
    1.34 +                                resultInfo.dup(inferenceContext.asInstType(resultInfo.pt));
    1.35                          check(tree, inferenceContext.asInstType(found), ownkind, pendingResult);
    1.36                      }
    1.37                  });
    1.38 -                return tree.type = resultInfo.pt;
    1.39              } else {
    1.40 -                if ((ownkind & ~resultInfo.pkind) == 0) {
    1.41 -                    owntype = resultInfo.check(tree, owntype);
    1.42 -                } else {
    1.43 -                    log.error(tree.pos(), "unexpected.type",
    1.44 -                            kindNames(resultInfo.pkind),
    1.45 -                            kindName(ownkind));
    1.46 -                    owntype = types.createErrorType(owntype);
    1.47 -                }
    1.48 +                owntype = resultInfo.check(tree, found);
    1.49              }
    1.50 +        } else {
    1.51 +            owntype = found;
    1.52          }
    1.53          tree.type = owntype;
    1.54          return owntype;
    1.55 @@ -2335,6 +2329,7 @@
    1.56                      currentTarget = infer.instantiateFunctionalInterface(that,
    1.57                              currentTarget, explicitParamTypes, resultInfo.checkContext);
    1.58                  }
    1.59 +                currentTarget = types.removeWildcards(currentTarget);
    1.60                  lambdaType = types.findDescriptorType(currentTarget);
    1.61              } else {
    1.62                  currentTarget = Type.recoveryType;
    1.63 @@ -2727,7 +2722,7 @@
    1.64                      resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK &&
    1.65                      isSerializable(currentTarget);
    1.66              if (currentTarget != Type.recoveryType) {
    1.67 -                currentTarget = targetChecker.visit(currentTarget, that);
    1.68 +                currentTarget = types.removeWildcards(targetChecker.visit(currentTarget, that));
    1.69                  desc = types.findDescriptorType(currentTarget);
    1.70              } else {
    1.71                  currentTarget = Type.recoveryType;

mercurial