changeset 58363:06d652252bc5 local-methods

8232703: [local-methods] Jshell test langtools/jdk/jshell/ComputeFQNsTest.java fails
author sadayapalam
date Mon, 21 Oct 2019 15:38:47 +0530
parents ace7fad5a6dc
children 48f8da9e2fd9
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java
diffstat 3 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Thu Oct 17 11:06:44 2019 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Mon Oct 21 15:38:47 2019 +0530
@@ -199,6 +199,7 @@
                                localEnv);
         } finally {
             deferredLintHandler.setPos(prevLintPos);
+            localEnv.info.scope.leave();
         }
 
         if (types.isSignaturePolymorphic(m)) {
@@ -218,7 +219,6 @@
         if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0)
             m.flags_field |= Flags.VARARGS;
 
-        localEnv.info.scope.leave();
         if (chk.checkUnique(tree.pos(), m, enclScope)) {
             if (isLocal) {
                 chk.checkTransparent(tree.pos(), m, enclScope);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu Oct 17 11:06:44 2019 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java	Mon Oct 21 15:38:47 2019 +0530
@@ -2584,6 +2584,7 @@
                 JCModifiers mods = F.at(Position.NOPOS).Modifiers(0);
                 JCExpression returnType = null;
                 if (token.kind == VOID) {
+                    returnType = to(F.at(pos).TypeIdent(TypeTag.VOID));
                     accept(VOID);
                 } else {
                     returnType = term(EXPR | TYPE);
--- a/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Thu Oct 17 11:06:44 2019 +0530
+++ b/src/jdk.jshell/share/classes/jdk/jshell/SourceCodeAnalysisImpl.java	Mon Oct 21 15:38:47 2019 +0530
@@ -564,6 +564,10 @@
     }
 
     private TreePath pathFor(CompilationUnitTree topLevel, SourcePositions sp, GeneralWrap wrap, int snippetEndPos) {
+        return pathFor(topLevel, sp, wrap, snippetEndPos, false);
+    }
+
+    private TreePath pathFor(CompilationUnitTree topLevel, SourcePositions sp, GeneralWrap wrap, int snippetEndPos, boolean wantPathToId) {
         int wrapEndPos = snippetEndPos == 0
                 ? wrap.snippetIndexToWrapIndex(snippetEndPos)
                 : wrap.snippetIndexToWrapIndex(snippetEndPos - 1) + 1;
@@ -582,8 +586,15 @@
                 if (start <= wrapEndPos && wrapEndPos <= end &&
                     (start != end || prevEnd != end || deepest[0] == null ||
                      deepest[0].getParentPath().getLeaf() != getCurrentPath().getLeaf())) {
-                    deepest[0] = new TreePath(getCurrentPath(), tree);
-                    return super.scan(tree, p);
+                    /* Hmmm, sometime we continue to scan after having found gold and toss it
+                       out for trash. Not entirely happy with this check, but it is really checking
+                       if we have found the identifier we are looking for at the cursor and if so
+                       not to trash it. FIXME (Srikanth)
+                    */
+                     if (!wantPathToId || prevEnd != wrapEndPos || deepest[0].getLeaf().getKind() != Kind.IDENTIFIER) {
+                        deepest[0] = new TreePath(getCurrentPath(), tree);
+                        return super.scan(tree, p);
+                     }
                 }
 
                 return null;
@@ -1529,7 +1540,7 @@
         return proc.taskFactory.analyze(codeWrap, at -> {
             SourcePositions sp = at.trees().getSourcePositions();
             CompilationUnitTree topLevel = at.firstCuTree();
-            TreePath tp = pathFor(topLevel, sp, codeWrap, codeFin.length());
+            TreePath tp = pathFor(topLevel, sp, codeWrap, codeFin.length(), true);
             if (tp.getLeaf().getKind() != Kind.IDENTIFIER) {
                 return new QualifiedNames(Collections.emptyList(), -1, true, false);
             }