8315588: JShell does not accept underscore from JEP 443 even with --enable-preview
Reviewed-by: jlahoda
This commit is contained in:
parent
15588e08ed
commit
2bf1863e24
@ -190,7 +190,7 @@ class CompletenessAnalyzer {
|
|||||||
EOF(TokenKind.EOF, 0), //
|
EOF(TokenKind.EOF, 0), //
|
||||||
ERROR(TokenKind.ERROR, XERRO), //
|
ERROR(TokenKind.ERROR, XERRO), //
|
||||||
IDENTIFIER(TokenKind.IDENTIFIER, XEXPR1|XDECL1|XTERM), //
|
IDENTIFIER(TokenKind.IDENTIFIER, XEXPR1|XDECL1|XTERM), //
|
||||||
UNDERSCORE(TokenKind.UNDERSCORE, XERRO), // _
|
UNDERSCORE(TokenKind.UNDERSCORE, XDECL1), // _
|
||||||
CLASS(TokenKind.CLASS, XEXPR|XDECL1|XBRACESNEEDED), // class decl (MAPPED: DOTCLASS)
|
CLASS(TokenKind.CLASS, XEXPR|XDECL1|XBRACESNEEDED), // class decl (MAPPED: DOTCLASS)
|
||||||
MONKEYS_AT(TokenKind.MONKEYS_AT, XEXPR|XDECL1), // @
|
MONKEYS_AT(TokenKind.MONKEYS_AT, XEXPR|XDECL1), // @
|
||||||
IMPORT(TokenKind.IMPORT, XDECL1|XSTART), // import -- consider declaration
|
IMPORT(TokenKind.IMPORT, XDECL1|XSTART), // import -- consider declaration
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 9999999
|
* @bug 8315851 8315588
|
||||||
* @summary Tests for unnamed variables
|
* @summary Tests for unnamed variables
|
||||||
* @library /tools/lib
|
* @library /tools/lib
|
||||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||||
@ -34,12 +34,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import jdk.jshell.SourceCodeAnalysis;
|
||||||
import jdk.jshell.VarSnippet;
|
import jdk.jshell.VarSnippet;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import jdk.jshell.JShell;
|
import jdk.jshell.JShell;
|
||||||
|
|
||||||
|
import static jdk.jshell.SourceCodeAnalysis.Completeness.COMPLETE;
|
||||||
|
import static jdk.jshell.SourceCodeAnalysis.Completeness.DEFINITELY_INCOMPLETE;
|
||||||
|
|
||||||
public class UnnamedTest extends KullaTesting {
|
public class UnnamedTest extends KullaTesting {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -50,6 +55,79 @@ public class UnnamedTest extends KullaTesting {
|
|||||||
Assert.assertEquals(getState().varValue(sn2), "\"x\"");
|
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
|
@Override
|
||||||
public void setUp(Consumer<JShell.Builder> bc) {
|
public void setUp(Consumer<JShell.Builder> bc) {
|
||||||
super.setUp(bc.andThen(b -> b.compilerOptions("--enable-preview", "--source", System.getProperty("java.specification.version"))));
|
super.setUp(bc.andThen(b -> b.compilerOptions("--enable-preview", "--source", System.getProperty("java.specification.version"))));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user