Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8366460

Access to a static final field is modeled differently in methods and in lambdas

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • repo-babylon
    • core-libs

      In methods, we load the field with FieldLoadOp.
      In lambdas, we refer to the (constant) value of the field.
      Here's an example:

      static final int Z = 42;

          /*
          func @"f" (%0 : java.type:"int")java.type:"int" -> {
            %1 : Var<java.type:"int"> = var %0 @"i";
            %2 : java.type:"int" = field.load @java.ref:"TestAST::Z:int";
            return %2;
          };
          */
          @CodeReflection
          static int f(int i) {
              return Z;
          }

          /*
          func @"quotedLambda" ()java.type:"jdk.incubator.code.Quoted" -> {
            %0 : java.type:"int" = constant @42;
            %1 : Var<java.type:"int"> = var %0 @"Z";
            %2 : java.type:"jdk.incubator.code.Quoted" = quoted ()java.type:"void" -> {
                %3 : java.type:"TestAST$QRunnable" = lambda ()java.type:"void" -> {
                    %4 : java.type:"int" = var.load %1;
                    %5 : Var<java.type:"int"> = var %4 @"x";
                    return;
                };
                yield %3;
            };
            return %2;
          };
          */
          QRunnable qr = () -> {
              int x = Z;
          };

            Unassigned Unassigned
            mabbay Mourad Abbay
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: