8315532: Compiler Implementation for Unnamed Variables & Patterns
8317221: Implementation for javax.lang.model for Unnamed Variables & Patterns Co-authored-by: Jan Lahoda <jlahoda@openjdk.org> Co-authored-by: Maurizio Cimadamore <mcimadamore@openjdk.org> Co-authored-by: Gavin Bierman <gbierman@openjdk.org> Co-authored-by: Brian Goetz <briangoetz@openjdk.org> Co-authored-by: Joe Darcy <darcy@openjdk.org> Co-authored-by: Aggelos Biboudis <abimpoudis@openjdk.org> Reviewed-by: jlahoda, mcimadamore
This commit is contained in:
parent
3934127b08
commit
c9d23c3940
@ -70,8 +70,6 @@ public @interface PreviewFeature {
|
||||
|
||||
@JEP(number=430, title="String Templates")
|
||||
STRING_TEMPLATES,
|
||||
@JEP(number=443, title="Unnamed Patterns and Variables")
|
||||
UNNAMED,
|
||||
@JEP(number=445, title="Unnamed Classes and Instance Main Methods")
|
||||
UNNAMED_CLASSES,
|
||||
@JEP(number=446, title="Scoped Values", status="Preview")
|
||||
|
@ -111,8 +111,7 @@ public interface VariableElement extends Element {
|
||||
* @jls 6.1 Declarations
|
||||
* @jls 14.4 Local Variable Declarations
|
||||
*
|
||||
* @since 21
|
||||
* @since 22
|
||||
*/
|
||||
@PreviewFeature(feature=PreviewFeature.Feature.UNNAMED, reflective = true)
|
||||
default boolean isUnnamed() { return getSimpleName().isEmpty(); }
|
||||
}
|
||||
|
@ -38,8 +38,7 @@ import jdk.internal.javac.PreviewFeature;
|
||||
*
|
||||
* @jls 14.30.1 Kinds of Patterns
|
||||
*
|
||||
* @since 21
|
||||
* @since 22
|
||||
*/
|
||||
@PreviewFeature(feature=PreviewFeature.Feature.UNNAMED)
|
||||
public interface AnyPatternTree extends PatternTree {
|
||||
}
|
||||
|
@ -230,9 +230,8 @@ public interface Tree {
|
||||
/**
|
||||
* Used for instances of {@link BindingPatternTree}.
|
||||
*
|
||||
* @since 21
|
||||
* @since 22
|
||||
*/
|
||||
@PreviewFeature(feature=PreviewFeature.Feature.UNNAMED)
|
||||
ANY_PATTERN(AnyPatternTree.class),
|
||||
|
||||
/**
|
||||
|
@ -273,9 +273,8 @@ public interface TreeVisitor<R,P> {
|
||||
* @param node the node being visited
|
||||
* @param p a parameter value
|
||||
* @return a result value
|
||||
* @since 21
|
||||
* @since 22
|
||||
*/
|
||||
@PreviewFeature(feature=PreviewFeature.Feature.UNNAMED)
|
||||
R visitAnyPattern(AnyPatternTree node, P p);
|
||||
|
||||
/**
|
||||
|
@ -649,10 +649,9 @@ public class SimpleTreeVisitor <R,P> implements TreeVisitor<R,P> {
|
||||
* @param node {@inheritDoc}
|
||||
* @param p {@inheritDoc}
|
||||
* @return the result of {@code defaultAction}
|
||||
* @since 21
|
||||
* @since 22
|
||||
*/
|
||||
@Override
|
||||
@PreviewFeature(feature=PreviewFeature.Feature.UNNAMED)
|
||||
public R visitAnyPattern(AnyPatternTree node, P p) {
|
||||
return defaultAction(node, p);
|
||||
}
|
||||
|
@ -211,7 +211,6 @@ public class Preview {
|
||||
return switch (feature) {
|
||||
case STRING_TEMPLATES -> true;
|
||||
case UNNAMED_CLASSES -> true;
|
||||
case UNNAMED_VARIABLES -> true;
|
||||
//Note: this is a backdoor which allows to optionally treat all features as 'preview' (for testing).
|
||||
//When real preview features will be added, this method can be implemented to return 'true'
|
||||
//for those selected features, and 'false' for all the others.
|
||||
|
@ -247,7 +247,7 @@ public enum Source {
|
||||
STRING_TEMPLATES(JDK21, Fragments.FeatureStringTemplates, DiagKind.PLURAL),
|
||||
UNNAMED_CLASSES(JDK21, Fragments.FeatureUnnamedClasses, DiagKind.PLURAL),
|
||||
WARN_ON_ILLEGAL_UTF8(MIN, JDK21),
|
||||
UNNAMED_VARIABLES(JDK21, Fragments.FeatureUnnamedVariables, DiagKind.PLURAL),
|
||||
UNNAMED_VARIABLES(JDK22, Fragments.FeatureUnnamedVariables, DiagKind.PLURAL),
|
||||
;
|
||||
|
||||
enum DiagKind {
|
||||
|
@ -653,8 +653,8 @@ public class JavacParser implements Parser {
|
||||
log.error(DiagnosticFlag.SYNTAX, token.pos, Errors.UseOfUnderscoreNotAllowedWithBrackets);
|
||||
}
|
||||
} else {
|
||||
if (preview.isEnabled() && Feature.UNNAMED_VARIABLES.allowedInSource(source)) {
|
||||
log.error(DiagnosticFlag.SYNTAX, token.pos, Errors.UseOfUnderscoreNotAllowed);
|
||||
if (Feature.UNNAMED_VARIABLES.allowedInSource(source)) {
|
||||
log.error(DiagnosticFlag.SYNTAX, token.pos, Errors.UseOfUnderscoreNotAllowedNonVariable);
|
||||
} else {
|
||||
log.error(DiagnosticFlag.SYNTAX, token.pos, Errors.UnderscoreAsIdentifier);
|
||||
}
|
||||
|
@ -3204,8 +3204,12 @@ compiler.err.underscore.as.identifier=\
|
||||
as of release 9, ''_'' is a keyword, and may not be used as an identifier
|
||||
|
||||
compiler.err.use.of.underscore.not.allowed=\
|
||||
as of release 21, the underscore keyword ''_'' is only allowed to declare\n\
|
||||
unnamed patterns, local variables, exception parameters or lambda parameters
|
||||
underscore not allowed here\n\
|
||||
as of release 9, ''_'' is a keyword, and may not be used as an identifier\n\
|
||||
as of release 22, ''_'' can be used as a name in the declaration of unnamed patterns, local variables, exception parameters or lambda parameters
|
||||
|
||||
compiler.err.use.of.underscore.not.allowed.non.variable=\
|
||||
underscore not allowed here
|
||||
|
||||
compiler.err.use.of.underscore.not.allowed.with.brackets=\
|
||||
the underscore keyword ''_'' is not allowed to be followed by brackets
|
||||
|
@ -324,7 +324,6 @@ public class TreeScanner extends Visitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreviewFeature(feature=PreviewFeature.Feature.UNNAMED)
|
||||
public void visitAnyPattern(JCAnyPattern that) {
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8312163
|
||||
* @summary Crash in dominance check when compiling unnamed patterns
|
||||
* @enablePreview
|
||||
* @compile/fail/ref=T8312163.out -XDrawDiagnostics T8312163.java
|
||||
*/
|
||||
|
||||
public class T8312163 {
|
||||
sealed interface A permits B {}
|
||||
record B() implements A {}
|
||||
|
@ -4,6 +4,4 @@ T8312163.java:33:18: compiler.err.pattern.dominated
|
||||
T8312163.java:39:18: compiler.err.pattern.dominated
|
||||
T8312163.java:49:18: compiler.err.pattern.dominated
|
||||
T8312163.java:54:18: compiler.err.pattern.dominated
|
||||
- compiler.note.preview.filename: T8312163.java, DEFAULT
|
||||
- compiler.note.preview.recompile
|
||||
6 errors
|
@ -2,7 +2,7 @@
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8314216
|
||||
* @summary Multiple patterns without unnamed variables
|
||||
* @compile/fail/ref=T8314216.out -XDrawDiagnostics --enable-preview --source ${jdk.version} T8314216.java
|
||||
* @compile/fail/ref=T8314216.out -XDrawDiagnostics T8314216.java
|
||||
*/
|
||||
|
||||
public class T8314216 {
|
||||
|
@ -1,5 +1,3 @@
|
||||
T8314216.java:13:23: compiler.err.invalid.case.label.combination
|
||||
T8314216.java:14:28: compiler.err.invalid.case.label.combination
|
||||
- compiler.note.preview.filename: T8314216.java, DEFAULT
|
||||
- compiler.note.preview.recompile
|
||||
2 errors
|
@ -2,8 +2,8 @@
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8314423
|
||||
* @summary Multiple patterns without unnamed variables
|
||||
* @compile/fail/ref=T8314423.out -XDrawDiagnostics T8314423.java
|
||||
* @compile --enable-preview --source ${jdk.version} T8314423.java
|
||||
* @compile/fail/ref=T8314423.out -XDrawDiagnostics --release 21 T8314423.java
|
||||
* @compile T8314423.java
|
||||
*/
|
||||
|
||||
public class T8314423 {
|
||||
|
@ -1,2 +1,2 @@
|
||||
T8314423.java:15:24: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.unnamed.variables)
|
||||
T8314423.java:15:24: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.unnamed.variables), 21, 22
|
||||
1 error
|
@ -2,8 +2,7 @@
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8304246
|
||||
* @summary Compiler Implementation for Unnamed patterns and variables
|
||||
* @enablePreview
|
||||
* @compile/ref=TwrLintUnderscore.out --enable-preview -source ${jdk.version} -Xlint:try -XDrawDiagnostics TwrLintUnderscore.java
|
||||
* @compile -Xlint:try -XDrawDiagnostics TwrLintUnderscore.java
|
||||
*/
|
||||
class TwrLintUnderscore implements AutoCloseable {
|
||||
private static void test1() {
|
||||
|
@ -1,2 +0,0 @@
|
||||
- compiler.note.preview.filename: TwrLintUnderscore.java, DEFAULT
|
||||
- compiler.note.preview.recompile
|
@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
// key: compiler.err.underscore.as.identifier
|
||||
// options: --release 21
|
||||
|
||||
class UnderscoreAsIdentifierError {
|
||||
String _ = null;
|
||||
|
@ -21,9 +21,10 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
// key: compiler.err.feature.not.supported.in.source.plural
|
||||
// key: compiler.misc.feature.unnamed.variables
|
||||
// key: compiler.warn.preview.feature.use.plural
|
||||
// options: --enable-preview -source ${jdk.version} -Xlint:preview
|
||||
// key: compiler.warn.source.no.system.modules.path
|
||||
// options: -source 21
|
||||
|
||||
public class UnderscoreInLambdaExpression {
|
||||
java.util.function.Function<String,String> f = _ -> "x";
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
// key: compiler.err.feature.not.supported.in.source.plural
|
||||
// key: compiler.misc.feature.unnamed.variables
|
||||
// options: -Xlint:-options --source 21
|
||||
|
||||
class UnnamedVariables {
|
||||
void test() {
|
||||
String _ = null;
|
||||
}
|
||||
}
|
@ -22,10 +22,7 @@
|
||||
*/
|
||||
|
||||
// key: compiler.err.use.of.underscore.not.allowed
|
||||
// options: --enable-preview -source ${jdk.version} -Xlint:preview
|
||||
|
||||
import java.util.function.*;
|
||||
|
||||
class UseOfUnderscoreNotAllowed {
|
||||
IntBinaryOperator f = (int x, int y) -> _ + x;
|
||||
private int a = 0, _ = 1;
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
// key: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
|
||||
import java.util.function.*;
|
||||
|
||||
class UseOfUnderscoreNotAllowedNonVar {
|
||||
IntBinaryOperator f = (int x, int y) -> _ + x;
|
||||
}
|
@ -22,9 +22,6 @@
|
||||
*/
|
||||
|
||||
// key: compiler.err.use.of.underscore.not.allowed.with.brackets
|
||||
// key: compiler.misc.feature.unnamed.variables
|
||||
// key: compiler.warn.preview.feature.use.plural
|
||||
// options: --enable-preview -source ${jdk.version} -Xlint:preview
|
||||
|
||||
class UseOfUnderscoreNotAllowedWithBrackets {
|
||||
void test() {
|
||||
|
@ -4,8 +4,8 @@
|
||||
* @author sogoel
|
||||
* @summary Test generation of warnings when '_' is used an identifier
|
||||
* @compile/fail/ref=IdentifierTest8.out --release 8 -Werror -XDrawDiagnostics -Xlint:-options IdentifierTest.java
|
||||
* @compile/fail/ref=IdentifierTest9.out -XDrawDiagnostics IdentifierTest.java
|
||||
* @compile/fail/ref=IdentifierTest21.out -source ${jdk.version} --enable-preview -XDrawDiagnostics IdentifierTest.java
|
||||
* @compile/fail/ref=IdentifierTest9.out --release 9 -XDrawDiagnostics IdentifierTest.java
|
||||
* @compile/fail/ref=IdentifierTest22.out -XDrawDiagnostics IdentifierTest.java
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,40 +1,38 @@
|
||||
IdentifierTest.java:42:11: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:45:16: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:47:22: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:52:13: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:52:23: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:54:13: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:56:13: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:64:67: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:71:13: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:72:14: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:73:18: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:80:13: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:80:15: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:82:13: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:82:15: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:89:10: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:89:38: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:95:14: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:102:17: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:102:26: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:119:20: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:124:10: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:129:17: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:132:17: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:139:24: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:139:33: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:140:39: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:145:15: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:146:13: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:151:15: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:152:17: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:42:11: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:45:16: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:47:22: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:52:13: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:52:23: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:54:13: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:56:13: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:64:67: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:71:13: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:72:14: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:73:18: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:80:13: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:80:15: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:82:13: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:82:15: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:89:10: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:89:38: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:95:14: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:102:17: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:102:26: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:119:20: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:124:10: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:129:17: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:132:17: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:139:24: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:139:33: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:140:39: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:145:15: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:146:13: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:151:15: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:152:17: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:158:16: compiler.err.use.of.underscore.not.allowed.with.brackets
|
||||
IdentifierTest.java:160:25: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:169:5: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:173:26: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:175:19: compiler.err.use.of.underscore.not.allowed
|
||||
IdentifierTest.java:181:11: compiler.err.use.of.underscore.not.allowed
|
||||
- compiler.note.preview.filename: IdentifierTest.java, DEFAULT
|
||||
- compiler.note.preview.recompile
|
||||
IdentifierTest.java:160:25: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:169:5: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:173:26: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:175:19: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
IdentifierTest.java:181:11: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
37 errors
|
@ -1,6 +1,6 @@
|
||||
IdentifierTest.java:42:11: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:45:16: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:46:20: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.unnamed.variables)
|
||||
IdentifierTest.java:46:20: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.unnamed.variables), 9, 22
|
||||
IdentifierTest.java:47:22: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:52:13: compiler.err.underscore.as.identifier
|
||||
IdentifierTest.java:52:23: compiler.err.underscore.as.identifier
|
||||
|
@ -2,8 +2,8 @@
|
||||
* @test /nodynamiccopyright/
|
||||
* @summary Check usages of underscore as identifier generate warnings
|
||||
* @compile/fail/ref=UnderscoreAsIdent8.out --release 8 -XDrawDiagnostics -Xlint:-options -Werror UnderscoreAsIdent.java
|
||||
* @compile/fail/ref=UnderscoreAsIdent9.out -XDrawDiagnostics -Werror UnderscoreAsIdent.java
|
||||
* @compile/fail/ref=UnderscoreAsIdent21.out -source ${jdk.version} --enable-preview -XDrawDiagnostics UnderscoreAsIdent.java
|
||||
* @compile/fail/ref=UnderscoreAsIdent9.out --release 9 -XDrawDiagnostics -Werror UnderscoreAsIdent.java
|
||||
* @compile/fail/ref=UnderscoreAsIdent22.out -XDrawDiagnostics UnderscoreAsIdent.java
|
||||
*/
|
||||
package _._;
|
||||
|
||||
|
@ -1,17 +1,15 @@
|
||||
UnderscoreAsIdent.java:8:9: compiler.err.use.of.underscore.not.allowed
|
||||
UnderscoreAsIdent.java:8:11: compiler.err.use.of.underscore.not.allowed
|
||||
UnderscoreAsIdent.java:10:8: compiler.err.use.of.underscore.not.allowed
|
||||
UnderscoreAsIdent.java:10:10: compiler.err.use.of.underscore.not.allowed
|
||||
UnderscoreAsIdent.java:12:7: compiler.err.use.of.underscore.not.allowed
|
||||
UnderscoreAsIdent.java:13:12: compiler.err.use.of.underscore.not.allowed
|
||||
UnderscoreAsIdent.java:14:10: compiler.err.use.of.underscore.not.allowed
|
||||
UnderscoreAsIdent.java:14:19: compiler.err.use.of.underscore.not.allowed
|
||||
UnderscoreAsIdent.java:19:25: compiler.err.use.of.underscore.not.allowed
|
||||
UnderscoreAsIdent.java:19:33: compiler.err.use.of.underscore.not.allowed
|
||||
UnderscoreAsIdent.java:25:9: compiler.err.use.of.underscore.not.allowed
|
||||
UnderscoreAsIdent.java:27:19: compiler.err.use.of.underscore.not.allowed
|
||||
UnderscoreAsIdent.java:29:9: compiler.err.use.of.underscore.not.allowed
|
||||
UnderscoreAsIdent.java:31:22: compiler.err.use.of.underscore.not.allowed
|
||||
- compiler.note.preview.filename: UnderscoreAsIdent.java, DEFAULT
|
||||
- compiler.note.preview.recompile
|
||||
UnderscoreAsIdent.java:8:9: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnderscoreAsIdent.java:8:11: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnderscoreAsIdent.java:10:8: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnderscoreAsIdent.java:10:10: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnderscoreAsIdent.java:12:7: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnderscoreAsIdent.java:13:12: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnderscoreAsIdent.java:14:10: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnderscoreAsIdent.java:14:19: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnderscoreAsIdent.java:19:25: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnderscoreAsIdent.java:19:33: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnderscoreAsIdent.java:25:9: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnderscoreAsIdent.java:27:19: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnderscoreAsIdent.java:29:9: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnderscoreAsIdent.java:31:22: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
14 errors
|
@ -6,7 +6,7 @@ UnderscoreAsIdent.java:12:7: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:13:12: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:14:10: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:14:19: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:16:16: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.unnamed.variables)
|
||||
UnderscoreAsIdent.java:16:16: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.unnamed.variables), 9, 22
|
||||
UnderscoreAsIdent.java:19:25: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:19:33: compiler.err.underscore.as.identifier
|
||||
UnderscoreAsIdent.java:25:9: compiler.err.underscore.as.identifier
|
||||
|
@ -2206,7 +2206,7 @@ public class JavacParserTest extends TestCase {
|
||||
/*public static final*/ _ /* = new Test() */ /*enum*/ ;
|
||||
} """,
|
||||
"""
|
||||
Test.java:3:5: compiler.err.underscore.as.identifier
|
||||
Test.java:3:5: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
"""),
|
||||
new TestCase("""
|
||||
package t;
|
||||
@ -2241,7 +2241,7 @@ public class JavacParserTest extends TestCase {
|
||||
/*public static final*/ _ /* = new Test() */ /*enum*/ ;
|
||||
} """,
|
||||
"""
|
||||
Test.java:3:5: compiler.err.underscore.as.identifier
|
||||
Test.java:3:5: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
"""),
|
||||
new TestCase("""
|
||||
package t;
|
||||
@ -2330,7 +2330,7 @@ public class JavacParserTest extends TestCase {
|
||||
/*public static final*/ A /* = new Test() */ /*enum*/ ;
|
||||
} """,
|
||||
"""
|
||||
Test.java:3:5: compiler.err.underscore.as.identifier
|
||||
Test.java:3:5: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
"""),
|
||||
};
|
||||
for (TestCase testCase : testCases) {
|
||||
|
@ -1,6 +1,4 @@
|
||||
T8314578.java:14:18: compiler.err.flows.through.from.pattern
|
||||
T8314578.java:15:18: compiler.err.flows.through.to.pattern
|
||||
T8314578.java:27:18: compiler.err.flows.through.to.pattern
|
||||
- compiler.note.preview.filename: T8314578.java, DEFAULT
|
||||
- compiler.note.preview.recompile
|
||||
3 errors
|
@ -2,9 +2,9 @@
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8314632
|
||||
* @summary Intra-case dominance check fails in the presence of a guard
|
||||
* @enablePreview
|
||||
* @compile/fail/ref=T8314632.out -XDrawDiagnostics T8314632.java
|
||||
*/
|
||||
|
||||
public class T8314632 {
|
||||
void test1(Object obj) {
|
||||
switch (obj) {
|
||||
|
@ -1,6 +1,4 @@
|
||||
T8314632.java:12:45: compiler.err.pattern.dominated
|
||||
T8314632.java:20:45: compiler.err.pattern.dominated
|
||||
T8314632.java:36:29: compiler.err.pattern.dominated
|
||||
- compiler.note.preview.filename: T8314632.java, DEFAULT
|
||||
- compiler.note.preview.recompile
|
||||
3 errors
|
@ -21,11 +21,10 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
/*
|
||||
* @test
|
||||
* @bug 8304246
|
||||
* @summary Compiler Implementation for Unnamed patterns and variables
|
||||
* @enablePreview
|
||||
* @compile Unnamed.java
|
||||
* @run main Unnamed
|
||||
*/
|
||||
@ -98,6 +97,9 @@ public class Unnamed {
|
||||
try (final Lock _ = null) { }
|
||||
try (@Foo Lock _ = null) { }
|
||||
|
||||
try (Lock _ = null) { }
|
||||
catch (Exception | Error _) { }
|
||||
|
||||
String[] strs = new String[] { "str1", "str2" };
|
||||
for (var _ : strs) {
|
||||
for (var _ : strs) {
|
||||
|
@ -1,8 +1,7 @@
|
||||
/**
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8304246 8309093
|
||||
* @summary Compiler Implementation for Unnamed patterns and variables
|
||||
* @enablePreview
|
||||
* @compile/fail/ref=UnnamedErrors.out -XDrawDiagnostics -XDshould-stop.at=FLOW UnnamedErrors.java
|
||||
*/
|
||||
public class UnnamedErrors {
|
||||
@ -111,6 +110,12 @@ public class UnnamedErrors {
|
||||
for (int _[] : new int[][]{new int[]{1}, new int[]{2}}) { }
|
||||
}
|
||||
|
||||
void testUnderscoreInExpression() {
|
||||
for(String s : _) {
|
||||
int i = 1;
|
||||
}
|
||||
}
|
||||
|
||||
class Lock implements AutoCloseable {
|
||||
@Override
|
||||
public void close() {}
|
||||
|
@ -1,37 +1,36 @@
|
||||
UnnamedErrors.java:9:17: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:10:17: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:11:20: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:11:26: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:11:32: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:12:17: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:8:17: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnnamedErrors.java:9:17: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnnamedErrors.java:10:20: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:10:26: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:10:32: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:11:17: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnnamedErrors.java:11:24: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:12:24: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:13:24: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:15:18: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:16:23: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:17:19: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:22:26: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:24:26: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:27:18: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:34:18: compiler.err.restricted.type.not.allowed.here: var
|
||||
UnnamedErrors.java:77:18: compiler.err.use.of.underscore.not.allowed
|
||||
UnnamedErrors.java:77:19: compiler.err.expected: token.identifier
|
||||
UnnamedErrors.java:82:40: compiler.err.expected2: :, ->
|
||||
UnnamedErrors.java:82:51: compiler.err.expected: =
|
||||
UnnamedErrors.java:82:58: compiler.err.expected: ';'
|
||||
UnnamedErrors.java:101:14: compiler.err.expected: =
|
||||
UnnamedErrors.java:102:22: compiler.err.expected: =
|
||||
UnnamedErrors.java:104:26: compiler.err.expected: =
|
||||
UnnamedErrors.java:110:13: compiler.err.use.of.underscore.not.allowed.with.brackets
|
||||
UnnamedErrors.java:111:18: compiler.err.use.of.underscore.not.allowed.with.brackets
|
||||
UnnamedErrors.java:11:17: compiler.err.already.defined: kindname.variable, x, kindname.class, UnnamedErrors
|
||||
UnnamedErrors.java:36:13: compiler.err.unconditional.pattern.and.default
|
||||
UnnamedErrors.java:45:18: compiler.err.pattern.dominated
|
||||
UnnamedErrors.java:54:29: compiler.err.flows.through.from.pattern
|
||||
UnnamedErrors.java:61:29: compiler.err.flows.through.from.pattern
|
||||
UnnamedErrors.java:68:32: compiler.err.flows.through.from.pattern
|
||||
UnnamedErrors.java:82:56: compiler.err.already.defined: kindname.variable, x2, kindname.method, guardErrors(java.lang.Object,int,int)
|
||||
UnnamedErrors.java:83:13: compiler.err.switch.mixing.case.types
|
||||
UnnamedErrors.java:90:30: compiler.err.pattern.dominated
|
||||
- compiler.note.preview.filename: UnnamedErrors.java, DEFAULT
|
||||
- compiler.note.preview.recompile
|
||||
34 errors
|
||||
UnnamedErrors.java:14:18: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnnamedErrors.java:15:23: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnnamedErrors.java:16:19: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnnamedErrors.java:21:26: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnnamedErrors.java:23:26: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnnamedErrors.java:26:18: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnnamedErrors.java:33:18: compiler.err.restricted.type.not.allowed.here: var
|
||||
UnnamedErrors.java:76:18: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnnamedErrors.java:76:19: compiler.err.expected: token.identifier
|
||||
UnnamedErrors.java:81:40: compiler.err.expected2: :, ->
|
||||
UnnamedErrors.java:81:51: compiler.err.expected: =
|
||||
UnnamedErrors.java:81:58: compiler.err.expected: ';'
|
||||
UnnamedErrors.java:100:14: compiler.err.expected: =
|
||||
UnnamedErrors.java:101:22: compiler.err.expected: =
|
||||
UnnamedErrors.java:103:26: compiler.err.expected: =
|
||||
UnnamedErrors.java:109:13: compiler.err.use.of.underscore.not.allowed.with.brackets
|
||||
UnnamedErrors.java:110:18: compiler.err.use.of.underscore.not.allowed.with.brackets
|
||||
UnnamedErrors.java:114:24: compiler.err.use.of.underscore.not.allowed.non.variable
|
||||
UnnamedErrors.java:10:17: compiler.err.already.defined: kindname.variable, x, kindname.class, UnnamedErrors
|
||||
UnnamedErrors.java:35:13: compiler.err.unconditional.pattern.and.default
|
||||
UnnamedErrors.java:44:18: compiler.err.pattern.dominated
|
||||
UnnamedErrors.java:53:29: compiler.err.flows.through.from.pattern
|
||||
UnnamedErrors.java:60:29: compiler.err.flows.through.from.pattern
|
||||
UnnamedErrors.java:67:32: compiler.err.flows.through.from.pattern
|
||||
UnnamedErrors.java:81:56: compiler.err.already.defined: kindname.variable, x2, kindname.method, guardErrors(java.lang.Object,int,int)
|
||||
UnnamedErrors.java:82:13: compiler.err.switch.mixing.case.types
|
||||
UnnamedErrors.java:89:30: compiler.err.pattern.dominated
|
||||
35 errors
|
Loading…
Reference in New Issue
Block a user