code: JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) {
          final JCTree newTree = new TreeCopier<Object>(make).copy(tree);
          Env<AttrContext> speculativeEnv = env.dup(newTree, env.info.dup(env.info.scope.dupUnshared()));
          speculativeEnv.info.scope.owner = env.info.scope.owner;
          Log.DeferredDiagnosticHandler deferredDiagnosticHandler =
                  new Log.DeferredDiagnosticHandler(log, new Filter<JCDiagnostic>() {
              public boolean accepts(final JCDiagnostic d) {
                  class PosScanner extends TreeScanner {
                      boolean found = false;
  
                      @Override
                      public void scan(JCTree tree) {
                          if (tree != null &&
                                  tree.pos() == d.getDiagnosticPosition()) {
                              found = true;
                          }
                          super.scan(tree);
                      }
                  };
                  PosScanner posScanner = new PosScanner();
                  posScanner.scan(newTree);
                  return posScanner.found;
              }
          });
          try {
              attr.attribTree(newTree, speculativeEnv, resultInfo);
              unenterScanner.scan(newTree);
              return newTree;
          } finally {
              unenterScanner.scan(newTree);
              log.popDiagnosticHandler(deferredDiagnosticHandler);
          }
      }
docs: Routine that performs speculative type-checking; the input AST node is
  cloned (to avoid side-effects cause by Attr) and compiler state is
  restored after type-checking. All diagnostics (but critical ones) are
  disabled during speculative type-checking.