< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ArgumentAttr.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

@@ -27,10 +27,11 @@
  
  import com.sun.tools.javac.code.Flags;
  import com.sun.tools.javac.code.Symbol;
  import com.sun.tools.javac.code.Symtab;
  import com.sun.tools.javac.code.Type;
+ import com.sun.tools.javac.code.Types;
  import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError;
  import com.sun.tools.javac.comp.Attr.ResultInfo;
  import com.sun.tools.javac.comp.Attr.TargetInfo;
  import com.sun.tools.javac.comp.Check.CheckContext;
  import com.sun.tools.javac.comp.DeferredAttr.AttrMode;

@@ -102,10 +103,12 @@
      private final JCDiagnostic.Factory diags;
      private final Attr attr;
      private final Symtab syms;
      private final Log log;
  
+     private final Types types;
+ 
      /** Attribution environment to be used. */
      private Env<AttrContext> env;
  
      /** Result of method attribution. */
      Type result;

@@ -126,10 +129,11 @@
          deferredAttr = DeferredAttr.instance(context);
          diags = JCDiagnostic.Factory.instance(context);
          attr = Attr.instance(context);
          syms = Symtab.instance(context);
          log = Log.instance(context);
+         types = Types.instance(context);
      }
  
      /**
       * Set the results of method attribution.
       */

@@ -557,21 +561,26 @@
              });
          }
  
          @Override
          Type overloadCheck(ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) {
-             try {
-                 //compute target-type; this logic could be shared with Attr
-                 TargetInfo targetInfo = attr.getTargetInfo(speculativeTree, resultInfo, argtypes());
-                 Type lambdaType = targetInfo.descriptor;
-                 Type currentTarget = targetInfo.target;
-                 //check compatibility
-                 checkLambdaCompatible(lambdaType, resultInfo);
-                 return currentTarget;
-             } catch (FunctionDescriptorLookupError ex) {
-                 resultInfo.checkContext.report(null, ex.getDiagnostic());
-                 return null; //cannot get here
+             if (types.isQuoted(resultInfo.pt)) {
+                 // quoted lambda - always correct
+                 return resultInfo.pt;
+             } else {
+                 try {
+                     //compute target-type; this logic could be shared with Attr
+                     TargetInfo targetInfo = attr.getTargetInfo(speculativeTree, resultInfo, argtypes());
+                     Type lambdaType = targetInfo.descriptor;
+                     Type currentTarget = targetInfo.target;
+                     //check compatibility
+                     checkLambdaCompatible(lambdaType, resultInfo);
+                     return currentTarget;
+                 } catch (FunctionDescriptorLookupError ex) {
+                     resultInfo.checkContext.report(null, ex.getDiagnostic());
+                     return null; //cannot get here
+                 }
              }
          }
  
          /** Check lambda against given target result */
          private void checkLambdaCompatible(Type descriptor, ResultInfo resultInfo) {
< prev index next >