Skip to content

Commit 77ca103

Browse files
committed
8257236: can't use var with a class named Z
Reviewed-by: sundar
1 parent 2243a17 commit 77ca103

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/jdk.jshell/share/classes/jdk/jshell/Wrap.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,16 @@ public static Wrap varWrap(String source, Wrap wtype, String brackets,
107107
// }
108108
// in do_it method:
109109
//return do_itAux();
110+
//find an unused name:
111+
String scratchName = "$";
112+
while (winit.wrapped().contains(scratchName)) {
113+
scratchName += "$";
114+
}
110115
Wrap waux = new CompoundWrap(
111-
" private static <Z> Z ", DOIT_METHOD_NAME + "Aux", "() throws Throwable {\n",
112-
wtype, brackets + " ", wname, "_ =\n ", winit, semi(winit),
113-
" @SuppressWarnings(\"unchecked\") Z ", wname, "__ = (Z)", wname, "_;\n",
114-
" return ", wname, "__;\n",
116+
" private static <" + scratchName + "> " + scratchName +" ", DOIT_METHOD_NAME + "Aux", "() throws Throwable {\n",
117+
wtype, brackets + " ", scratchName, "_ =\n ", winit, semi(winit),
118+
" @SuppressWarnings(\"unchecked\") ", scratchName, " ", scratchName, "__ = (", scratchName, ")", scratchName, "_;\n",
119+
" return ", scratchName, "__;\n",
115120
"}"
116121
);
117122
components.add(waux);

test/langtools/jdk/jshell/VariablesTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
/*
2525
* @test
26-
* @bug 8144903 8177466 8191842 8211694 8213725 8239536
26+
* @bug 8144903 8177466 8191842 8211694 8213725 8239536 8257236
2727
* @summary Tests for EvaluationState.variables
2828
* @library /tools/lib
2929
* @modules jdk.compiler/com.sun.tools.javac.api
@@ -400,6 +400,13 @@ public void lvti() {
400400
assertEval("r15a.add(\"a\");");
401401
assertEval("var r15b = r15a.get(0);");
402402
assertEval("r15b", "\"a\"");
403+
assertEval("class Z { }");
404+
assertEval("var r16a = new Z();");
405+
assertEval("var r16b = (Runnable) () -> {int r16b_; int r16b__;};");
406+
assertEval("class $ { }");
407+
assertEval("var r16c = new $();");
408+
assertEval("$ r16d() { return null; }");
409+
assertEval("var r16d = r16d();");
403410
}
404411

405412
public void test8191842() {

0 commit comments

Comments
 (0)