8189248: Jshell: error with mutually dependent snippets, when one must be replaced
authorjlahoda
Thu, 07 Dec 2017 19:24:27 +0100
changeset 48208 0a8db756a7e7
parent 48207 acfac57f4c35
child 48209 5fb7750f22cd
8189248: Jshell: error with mutually dependent snippets, when one must be replaced Summary: Ensuring proper imports are generated for mutually dependent snippets if one of them is replaced. Reviewed-by: rfield
src/jdk.jshell/share/classes/jdk/jshell/Eval.java
test/langtools/jdk/jshell/ClassesTest.java
--- a/src/jdk.jshell/share/classes/jdk/jshell/Eval.java	Thu Dec 07 10:18:22 2017 -0800
+++ b/src/jdk.jshell/share/classes/jdk/jshell/Eval.java	Thu Dec 07 19:24:27 2017 +0100
@@ -834,6 +834,8 @@
                         if (!toReplace.isEmpty()) {
                             replaced.addAll(toReplace);
                             replaced.stream().forEach(Unit::markForReplacement);
+                            //ensure correct classnames are set in the snippets:
+                            replaced.stream().forEach(u -> u.setWrap(ins, legit));
                         }
 
                         return toReplace.isEmpty() ? Result.SUCESS : Result.FAILURE;
--- a/test/langtools/jdk/jshell/ClassesTest.java	Thu Dec 07 10:18:22 2017 -0800
+++ b/test/langtools/jdk/jshell/ClassesTest.java	Thu Dec 07 19:24:27 2017 +0100
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8145239 8129559 8080354
+ * @bug 8145239 8129559 8080354 8189248
  * @summary Tests for EvaluationState.classes
  * @build KullaTesting TestingInputStream ExpectedDiagnostic
  * @run testng ClassesTest
@@ -41,6 +41,7 @@
 import org.testng.annotations.Test;
 
 import jdk.jshell.Diag;
+import jdk.jshell.Snippet.Status;
 import static java.util.stream.Collectors.toList;
 import static jdk.jshell.Snippet.Status.VALID;
 import static jdk.jshell.Snippet.Status.RECOVERABLE_NOT_DEFINED;
@@ -327,4 +328,24 @@
         VarSnippet variableKey = varKey(assertEval("a.x;"));
         assertEquals(variableKey.typeName(), "A.I1");
     }
+
+    public void testCircular() {
+        assertEval("import java.util.function.Supplier;");
+        TypeDeclSnippet aClass =
+                classKey(assertEval("public class A<T> {\n" +
+                                    "  private class SomeClass {}\n" +
+                                    "  public Supplier<T> m() {\n" +
+                                    "    return new B<>(this);\n" +
+                                    "  }\n" +
+                                    "}",
+                                   added(RECOVERABLE_DEFINED)));
+        assertEval("public class B<T> implements Supplier<T> {\n" +
+                   "  public B(A<T> a) {}\n" +
+                   "  public T get() {return null;}\n" +
+                   "}",
+                   added(VALID),
+                   ste(aClass, Status.RECOVERABLE_DEFINED, Status.VALID, true, null));
+        assertEval("new A()");
+    }
+
 }