8315588: JShell does not accept underscore from JEP 443 even with --enable-preview

Reviewed-by: jlahoda
This commit is contained in:
Aggelos Biboudis 2023-10-17 12:55:31 +00:00 committed by Jan Lahoda
parent 15588e08ed
commit 2bf1863e24
2 changed files with 80 additions and 2 deletions

View File

@ -190,7 +190,7 @@ class CompletenessAnalyzer {
EOF(TokenKind.EOF, 0), //
ERROR(TokenKind.ERROR, XERRO), //
IDENTIFIER(TokenKind.IDENTIFIER, XEXPR1|XDECL1|XTERM), //
UNDERSCORE(TokenKind.UNDERSCORE, XERRO), // _
UNDERSCORE(TokenKind.UNDERSCORE, XDECL1), // _
CLASS(TokenKind.CLASS, XEXPR|XDECL1|XBRACESNEEDED), // class decl (MAPPED: DOTCLASS)
MONKEYS_AT(TokenKind.MONKEYS_AT, XEXPR|XDECL1), // @
IMPORT(TokenKind.IMPORT, XDECL1|XSTART), // import -- consider declaration

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 9999999
* @bug 8315851 8315588
* @summary Tests for unnamed variables
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
@ -34,12 +34,17 @@
*/
import java.util.function.Consumer;
import jdk.jshell.SourceCodeAnalysis;
import jdk.jshell.VarSnippet;
import org.testng.Assert;
import org.testng.annotations.Test;
import jdk.jshell.JShell;
import static jdk.jshell.SourceCodeAnalysis.Completeness.COMPLETE;
import static jdk.jshell.SourceCodeAnalysis.Completeness.DEFINITELY_INCOMPLETE;
public class UnnamedTest extends KullaTesting {
@Test
@ -50,6 +55,79 @@ public class UnnamedTest extends KullaTesting {
Assert.assertEquals(getState().varValue(sn2), "\"x\"");
}
static final String[] definitely_incomplete = new String[]{
"int _ = ",
"int m(String v, int r) {\n" +
" try {\n" +
" return Integer.parseInt(v, r);\n" +
" } catch (NumberFormatException _) {",
"try (final Lock _ = ",
"try (Lock _ = null) {\n" +
" try (Lock _ = null) {",
"for (var _ : strs",
"TwoParams p1 = (_, _) ->",
"for (int _ = 0, _ = 1, x = 1;",
"if (r instanceof R(_"
};
static final String[] complete = new String[]{
"int _ = 42;",
"int m(String v, int r) {\n" +
" try {\n" +
" return Integer.parseInt(v, r);\n" +
" } catch (NumberFormatException _) { } }",
"try (final Lock _ = TEST) {}",
"try (Lock _ = null) {\n" +
" try (Lock _ = null) { } }",
"for (var _ : strs) { }",
"TwoParams p1 = (_, _) -> {};",
"for (int _ = 0, _ = 1, x = 1; x <= 1 ; x++) {}",
"if (r instanceof R(_)) { }"
};
private void assertStatus(String input, SourceCodeAnalysis.Completeness status, String source) {
String augSrc;
switch (status) {
case COMPLETE_WITH_SEMI:
augSrc = source + ";";
break;
case DEFINITELY_INCOMPLETE:
augSrc = null;
break;
case CONSIDERED_INCOMPLETE:
augSrc = source + ";";
break;
case EMPTY:
case COMPLETE:
case UNKNOWN:
augSrc = source;
break;
default:
throw new AssertionError();
}
assertAnalyze(input, status, augSrc);
}
private void assertStatus(String[] ins, SourceCodeAnalysis.Completeness status) {
for (String input : ins) {
assertStatus(input, status, input);
}
}
@Test
public void test_definitely_incomplete() {
assertStatus(definitely_incomplete, DEFINITELY_INCOMPLETE);
}
@Test
public void test_definitely_complete() {
assertStatus(complete, COMPLETE);
}
@Override
public void setUp(Consumer<JShell.Builder> bc) {
super.setUp(bc.andThen(b -> b.compilerOptions("--enable-preview", "--source", System.getProperty("java.specification.version"))));