8250625: Compiler implementation of Pattern Matching for instanceof (Final)

Reviewed-by: vromero
This commit is contained in:
Jan Lahoda 2020-11-05 08:01:33 +00:00
parent 60e4aca846
commit 18bc95ba51
86 changed files with 230 additions and 312 deletions

View file

@ -1,2 +1,2 @@
T4881267.java:10:34: compiler.err.illegal.generic.type.for.instof
T4881267.java:10:21: compiler.err.instanceof.reifiable.not.safe: java.lang.Object, T
1 error

View file

@ -399,14 +399,14 @@ public class CombinationsTargetTest2 extends ClassfileTestHelper {
case src7p: // (repeating) type annotations in use of instanceof with type test pattern
/*
* class Test10{
* String data = "test";
* Object data = "test";
* boolean dataIsString = ( data instanceof @A @B @A @B String str);
* }
*/
source = new String( source +
"// " + src.description + "\n" +
"class "+ testname + "{\n" +
" String data = \"test\";\n" +
" Object data = \"test\";\n" +
" boolean dataIsString = ( data instanceof _As_ _Bs_ String str && str.isEmpty());\n" +
"}\n").concat(sourceBase).replace("_OTHER_", annot2).replace("_As_",As).replace("_Bs_",Bs) +
"\n\n";
@ -455,7 +455,7 @@ public class CombinationsTargetTest2 extends ClassfileTestHelper {
source = new String( source +
"// " + src.description + "\n" +
"class "+ testname + "{\n" +
" String data = \"test\";\n" +
" Object data = \"test\";\n" +
" Boolean isString() { \n" +
" if( data instanceof _As_ _Bs_ String str)\n" +
" return true;\n" +

View file

@ -161,7 +161,6 @@ compiler.misc.locn.module_source_path # fragment uninter
compiler.misc.locn.system_modules # fragment uninteresting in and of itself
compiler.misc.locn.upgrade_module_path # fragment uninteresting in and of itself
compiler.misc.inferred.do.not.conform.to.eq.bounds # hard to generate, could probably be removed
compiler.err.feature.not.supported.in.source # Generated for using diamond before source 7
# The following are new module-related messages, that need new examples to be created
compiler.err.duplicate.module.on.path

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2020, 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
@ -21,14 +21,13 @@
* questions.
*/
// key: compiler.err.feature.not.supported.in.source.plural
// key: compiler.misc.feature.reifiable.types.instanceof
// key: compiler.warn.preview.feature.use.plural
// options: --enable-preview -source ${jdk.version} -Xlint:preview
// options: -source 15 -Xlint:-options
class PatternMatchingInstanceof {
boolean m(I<String> i) {
return i instanceof C<String>;
}
interface I<T> {}
class C<T> implements I<T> {}
import java.util.*;
class FeatureReifiableTypesInstanceof {
List o;
boolean b = (o instanceof List<String>);
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 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
@ -21,11 +21,10 @@
* questions.
*/
// key: compiler.err.illegal.generic.type.for.instof
// key: compiler.err.instanceof.pattern.no.subtype
import java.util.*;
class IllegalInstanceof {
List o;
boolean b = (o instanceof List<String>);
class InstanceofPatternNoSubtype {
boolean test(Object o) {
return o instanceof Object obj;
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, 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
@ -22,9 +22,6 @@
*/
// key: compiler.err.instanceof.reifiable.not.safe
// key: compiler.note.preview.filename
// key: compiler.note.preview.recompile
// options: --enable-preview -source ${jdk.version}
import java.util.List;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, 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
@ -22,9 +22,6 @@
*/
// key: compiler.err.match.binding.exists
// key: compiler.note.preview.filename
// key: compiler.note.preview.recompile
// options: --enable-preview -source ${jdk.version}
class MatchBindingExists {
public void test(Object o1, Object o2) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2020, 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
@ -22,8 +22,8 @@
*/
// key: compiler.misc.feature.pattern.matching.instanceof
// key: compiler.warn.preview.feature.use
// options: --enable-preview -source ${jdk.version} -Xlint:preview
// key: compiler.err.feature.not.supported.in.source
// options: -source 15 -Xlint:-options
class PatternMatchingInstanceof {
boolean m(Object o) {

View file

@ -1,2 +1,2 @@
InstanceOf2.java:12:48: compiler.err.illegal.generic.type.for.instof
InstanceOf2.java:12:29: compiler.err.instanceof.reifiable.not.safe: java.lang.Class<compiler.misc.type.captureof: 1, ? extends InstanceOf2>, java.lang.Class<InstanceOf2>
1 error

View file

@ -4,7 +4,7 @@
* @summary the type in an instanceof expression must be reifiable
* @author seligman
*
* @compile/fail/ref=InstanceOf3.out -XDrawDiagnostics InstanceOf3.java
* @compile/fail/ref=InstanceOf3.out -XDrawDiagnostics -source 15 -Xlint:-options InstanceOf3.java
*/
public class InstanceOf3 {

View file

@ -1,2 +1,2 @@
InstanceOf3.java:12:48: compiler.err.illegal.generic.type.for.instof
InstanceOf3.java:12:32: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.reifiable.types.instanceof), 15, 16
1 error

View file

@ -0,0 +1,5 @@
BadTest.java:19:50: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: List<java.lang.Object>, List<Cell<java.lang.String>>)
BadTest.java:23:48: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: List<java.lang.Object>, List<java.lang.String>)
BadTest.java:24:54: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: List<java.lang.Object>, List<Cell<java.lang.String>>)
BadTest.java:26:38: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.reifiable.types.instanceof), 15, 16
4 errors

View file

@ -3,6 +3,7 @@
* @summary Negative regression test from odersky
* @author odersky
*
* @compile/fail/ref=BadTest-old.out -XDrawDiagnostics -source 15 -Xlint:-options BadTest.java
* @compile/fail/ref=BadTest.out -XDrawDiagnostics BadTest.java
*/

View file

@ -1,5 +1,5 @@
BadTest.java:18:50: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: List<java.lang.Object>, List<Cell<java.lang.String>>)
BadTest.java:22:48: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: List<java.lang.Object>, List<java.lang.String>)
BadTest.java:23:54: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: List<java.lang.Object>, List<Cell<java.lang.String>>)
BadTest.java:25:53: compiler.err.illegal.generic.type.for.instof
BadTest.java:19:50: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: List<java.lang.Object>, List<Cell<java.lang.String>>)
BadTest.java:23:48: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: List<java.lang.Object>, List<java.lang.String>)
BadTest.java:24:54: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: List<java.lang.Object>, List<Cell<java.lang.String>>)
BadTest.java:26:35: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: List<java.lang.Object>, List<java.lang.String>)
4 errors

View file

@ -2,7 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8231827
* @summary Clashing bindings are reported correctly
* @compile/fail/ref=BindingsExistTest.out -XDrawDiagnostics --enable-preview -source ${jdk.version} BindingsExistTest.java
* @compile/fail/ref=BindingsExistTest.out -XDrawDiagnostics BindingsExistTest.java
*/
public class BindingsExistTest {
public void t(Object o1, Object o2) {

View file

@ -4,6 +4,4 @@ BindingsExistTest.java:16:35: compiler.err.already.defined: kindname.variable, k
BindingsExistTest.java:19:34: compiler.err.already.defined: kindname.variable, s2, kindname.method, t(java.lang.Object,java.lang.Object)
BindingsExistTest.java:22:20: compiler.err.already.defined: kindname.variable, s3, kindname.method, t(java.lang.Object,java.lang.Object)
BindingsExistTest.java:28:16: compiler.err.already.defined: kindname.variable, s4, kindname.method, t(java.lang.Object,java.lang.Object)
- compiler.note.preview.filename: BindingsExistTest.java
- compiler.note.preview.recompile
6 errors

View file

@ -25,8 +25,8 @@
* @test
* @bug 8231827
* @summary Basic tests for bindings from instanceof
* @compile --enable-preview -source ${jdk.version} BindingsTest1.java
* @run main/othervm --enable-preview BindingsTest1
* @compile BindingsTest1.java
* @run main BindingsTest1
*/
public class BindingsTest1 {

View file

@ -2,7 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8231827
* @summary Basic tests for bindings from instanceof - tests for merging pattern variables
* @compile/fail/ref=BindingsTest1Merging.out -XDrawDiagnostics --enable-preview -source ${jdk.version} BindingsTest1Merging.java
* @compile/fail/ref=BindingsTest1Merging.out -XDrawDiagnostics BindingsTest1Merging.java
*/
public class BindingsTest1Merging {

View file

@ -7,6 +7,4 @@ BindingsTest1Merging.java:44:21: compiler.err.match.binding.exists
BindingsTest1Merging.java:50:36: compiler.err.match.binding.exists
BindingsTest1Merging.java:56:39: compiler.err.match.binding.exists
BindingsTest1Merging.java:62:42: compiler.err.match.binding.exists
- compiler.note.preview.filename: BindingsTest1Merging.java
- compiler.note.preview.recompile
9 errors

View file

@ -2,7 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8231827
* @summary Ensure that scopes arising from conditionalExpressions are handled corrected.
* @compile/fail/ref=BindingsTest2.out -XDrawDiagnostics -XDshould-stop.at=FLOW --enable-preview -source ${jdk.version} BindingsTest2.java
* @compile/fail/ref=BindingsTest2.out -XDrawDiagnostics -XDshould-stop.at=FLOW BindingsTest2.java
*/
public class BindingsTest2 {
public static boolean Ktrue() { return true; }

View file

@ -49,6 +49,4 @@ BindingsTest2.java:241:17: compiler.err.cant.resolve.location: kindname.variable
BindingsTest2.java:135:17: compiler.err.unreachable.stmt
BindingsTest2.java:160:17: compiler.err.unreachable.stmt
BindingsTest2.java:185:17: compiler.err.unreachable.stmt
- compiler.note.preview.filename: BindingsTest2.java
- compiler.note.preview.recompile
51 errors

View file

@ -95,10 +95,7 @@ public class BreakAndLoops extends ComboInstance<BreakAndLoops> {
case "NESTED" -> brk;
case "BODY" -> innerLabel;
default -> throw new UnsupportedOperationException(pname);
})
.withOption("--enable-preview")
.withOption("-source")
.withOption(String.valueOf(Runtime.version().feature()));
});
task.generate(result -> {
boolean shouldPass;

View file

@ -2,7 +2,7 @@
* @test /nodynamicopyright/
* @bug 8231827
* @summary Match which involves a cast conversion
* @compile/fail/ref=CastConversionMatch.out -XDrawDiagnostics --enable-preview -source ${jdk.version} CastConversionMatch.java
* @compile/fail/ref=CastConversionMatch.out -XDrawDiagnostics CastConversionMatch.java
*/
public class CastConversionMatch {

View file

@ -1,4 +1,2 @@
CastConversionMatch.java:11:26: compiler.err.type.found.req: int, (compiler.misc.type.req.class.array)
- compiler.note.preview.filename: CastConversionMatch.java
- compiler.note.preview.recompile
1 error

View file

@ -85,10 +85,7 @@ public class ConditionalTest extends ComboInstance<ConditionalTest> {
case "TRUE" -> trueSec;
case "FALSE" -> falseSec;
default -> throw new UnsupportedOperationException(pname);
})
.withOption("--enable-preview")
.withOption("-source")
.withOption(String.valueOf(Runtime.version().feature()));
});
task.analyze(result -> {
boolean shouldPass;

View file

@ -2,7 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8231827
* @summary Basic pattern bindings scope test
* @compile/fail/ref=DuplicateBindingTest.out -XDrawDiagnostics --enable-preview -source ${jdk.version} DuplicateBindingTest.java
* @compile/fail/ref=DuplicateBindingTest.out -XDrawDiagnostics DuplicateBindingTest.java
*/
public class DuplicateBindingTest {
@ -10,17 +10,17 @@ public class DuplicateBindingTest {
int f;
public static boolean main(String[] args) {
Object o1 = "";
Object o2 = "";
if (args != null) {
int s;
if (args[0] instanceof String s) { // NOT OK. Redef same scope.
if (o1 instanceof String s) { // NOT OK. Redef same scope.
}
if (args[0] instanceof String f) { // OK to redef field.
if (o1 instanceof String f) { // OK to redef field.
}
}
Object o1 = "";
Object o2 = "";
if (o1 instanceof String s && o2 instanceof String s) {} //error - already in scope on RHS (in scope due to LHS when true)
if (o1 instanceof String s && !(o2 instanceof String s)) {} //error - already in scope on RHS (in scope due to LHS when true)

View file

@ -1,4 +1,4 @@
DuplicateBindingTest.java:16:43: compiler.err.already.defined: kindname.variable, s, kindname.method, main(java.lang.String[])
DuplicateBindingTest.java:18:38: compiler.err.already.defined: kindname.variable, s, kindname.method, main(java.lang.String[])
DuplicateBindingTest.java:25:60: compiler.err.match.binding.exists
DuplicateBindingTest.java:26:62: compiler.err.match.binding.exists
DuplicateBindingTest.java:27:39: compiler.err.match.binding.exists
@ -22,6 +22,4 @@ DuplicateBindingTest.java:50:102: compiler.err.match.binding.exists
DuplicateBindingTest.java:51:73: compiler.err.match.binding.exists
DuplicateBindingTest.java:54:69: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, DuplicateBindingTest, null)
DuplicateBindingTest.java:55:44: compiler.err.cant.resolve.location: kindname.variable, s, , , (compiler.misc.location: kindname.class, DuplicateBindingTest, null)
- compiler.note.preview.filename: DuplicateBindingTest.java
- compiler.note.preview.recompile
24 errors

View file

@ -2,7 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8187420 8231827
* @summary Error message mentions relevant types transposed
* @compile/fail/ref=EnsureTypesOrderTest.out -XDrawDiagnostics --enable-preview -source ${jdk.version} EnsureTypesOrderTest.java
* @compile/fail/ref=EnsureTypesOrderTest.out -XDrawDiagnostics EnsureTypesOrderTest.java
*/
public class EnsureTypesOrderTest {
public static void main(String [] args) {

View file

@ -1,4 +1,2 @@
EnsureTypesOrderTest.java:9:13: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String[], java.lang.String)
- compiler.note.preview.filename: EnsureTypesOrderTest.java
- compiler.note.preview.recompile
1 error

View file

@ -25,8 +25,8 @@
* @test
* @bug 8231827
* @summary All example code from "Pattern Matching for Java" document, released April 2017, adjusted to current state (no switches, etc)
* @compile --enable-preview -source ${jdk.version} ExamplesFromProposal.java
* @run main/othervm --enable-preview ExamplesFromProposal
* @compile ExamplesFromProposal.java
* @run main ExamplesFromProposal
*/
interface Node {

View file

@ -2,7 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8231827
* @summary Ensure that in type test patterns, the predicate is not trivially provable false.
* @compile/fail/ref=ImpossibleTypeTest.out -XDrawDiagnostics --enable-preview -source ${jdk.version} ImpossibleTypeTest.java
* @compile/fail/ref=ImpossibleTypeTest.out -XDrawDiagnostics ImpossibleTypeTest.java
*/
public class ImpossibleTypeTest {

View file

@ -1,5 +1,3 @@
ImpossibleTypeTest.java:14:13: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.Integer, java.lang.String)
ImpossibleTypeTest.java:17:26: compiler.err.cant.resolve.location: kindname.class, Undefined, , , (compiler.misc.location: kindname.class, ImpossibleTypeTest, null)
- compiler.note.preview.filename: ImpossibleTypeTest.java
- compiler.note.preview.recompile
2 errors

View file

@ -26,8 +26,8 @@
* @bug 8231827
* @summary Ensure the LV table entries are generated for bindings
* @modules jdk.jdeps/com.sun.tools.classfile
* @compile -g --enable-preview -source ${jdk.version} LocalVariableTable.java
* @run main/othervm --enable-preview LocalVariableTable
* @compile -g LocalVariableTable.java
* @run main LocalVariableTable
*/
import java.io.*;

View file

@ -2,7 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8231827
* @summary Basic pattern bindings scope test
* @compile/fail/ref=MatchBindingScopeTest.out -XDrawDiagnostics --enable-preview -source ${jdk.version} MatchBindingScopeTest.java
* @compile/fail/ref=MatchBindingScopeTest.out -XDrawDiagnostics MatchBindingScopeTest.java
*/
public class MatchBindingScopeTest {

View file

@ -11,6 +11,4 @@ MatchBindingScopeTest.java:56:48: compiler.err.cant.resolve.location: kindname.v
MatchBindingScopeTest.java:57:32: compiler.err.cant.resolve.location: kindname.variable, j, , , (compiler.misc.location: kindname.class, MatchBindingScopeTest, null)
MatchBindingScopeTest.java:62:23: compiler.err.cant.resolve.location: kindname.variable, j, , , (compiler.misc.location: kindname.class, MatchBindingScopeTest, null)
MatchBindingScopeTest.java:65:23: compiler.err.cant.resolve.location: kindname.variable, j, , , (compiler.misc.location: kindname.class, MatchBindingScopeTest, null)
- compiler.note.preview.filename: MatchBindingScopeTest.java
- compiler.note.preview.recompile
13 errors

View file

@ -0,0 +1,22 @@
/*
* @test /nodynamiccopyright/
* @bug 8250625
* @summary Verify pattern matching test which is always true produces an error
* @compile/fail/ref=NoSubtypeCheck.out -XDrawDiagnostics NoSubtypeCheck.java
*/
public class NoSubtypeCheck {
public static void main(Object o, String s, List<String> l) {
boolean b1 = o instanceof Object v1;
boolean b2 = o instanceof String v2;
boolean b3 = s instanceof Object v3;
boolean b4 = s instanceof String v4;
boolean b5 = l instanceof List<String> v5;
boolean b6 = l instanceof List2<String> v6;
boolean b7 = undef instanceof String v7;
boolean b8 = o instanceof Undef v7;
}
public interface List<T> {}
public interface List2<T> extends List<T> {}
}

View file

@ -0,0 +1,7 @@
NoSubtypeCheck.java:10:24: compiler.err.instanceof.pattern.no.subtype: java.lang.Object, java.lang.Object
NoSubtypeCheck.java:12:24: compiler.err.instanceof.pattern.no.subtype: java.lang.Object, java.lang.String
NoSubtypeCheck.java:13:24: compiler.err.instanceof.pattern.no.subtype: java.lang.String, java.lang.String
NoSubtypeCheck.java:14:24: compiler.err.instanceof.pattern.no.subtype: NoSubtypeCheck.List<java.lang.String>, NoSubtypeCheck.List<java.lang.String>
NoSubtypeCheck.java:16:22: compiler.err.cant.resolve.location: kindname.variable, undef, , , (compiler.misc.location: kindname.class, NoSubtypeCheck, null)
NoSubtypeCheck.java:17:35: compiler.err.cant.resolve.location: kindname.class, Undef, , , (compiler.misc.location: kindname.class, NoSubtypeCheck, null)
6 errors

View file

@ -27,8 +27,8 @@
* @summary Verify there are no unnecessary checkcasts and conditions generated
* for the pattern matching in instanceof.
* @modules jdk.jdeps/com.sun.tools.classfile
* @compile --enable-preview -source ${jdk.version} NoUnnecessaryCast.java
* @run main/othervm --enable-preview NoUnnecessaryCast
* @compile NoUnnecessaryCast.java
* @run main NoUnnecessaryCast
*/
import java.io.File;

View file

@ -25,8 +25,7 @@
* @test
* @bug 8231827
* @summary Testing pattern matching against the null constant
* @compile --enable-preview -source ${jdk.version} NullsInPatterns.java
* @run main/othervm --enable-preview NullsInPatterns
* @compile/fail/ref=NullsInPatterns.out -XDrawDiagnostics NullsInPatterns.java
*/
import java.util.List;

View file

@ -0,0 +1,3 @@
NullsInPatterns.java:35:18: compiler.err.instanceof.pattern.no.subtype: java.util.List, compiler.misc.type.null
NullsInPatterns.java:46:18: compiler.err.instanceof.pattern.no.subtype: java.util.List<?>, compiler.misc.type.null
2 errors

View file

@ -26,7 +26,7 @@
* @bug 8231827
* @summary Check proper positions.
* @build PatternMatchPosTest
* @compile/ref=PatternMatchPosTest.out -processor PatternMatchPosTest -Xlint:unchecked -XDrawDiagnostics --enable-preview -source ${jdk.version} PatternMatchPosTestData.java
* @compile/ref=PatternMatchPosTest.out -processor PatternMatchPosTest -Xlint:unchecked -XDrawDiagnostics PatternMatchPosTestData.java
*/
import java.io.IOException;
@ -85,8 +85,10 @@ public class PatternMatchPosTest extends AbstractProcessor {
if (print) {
int start = (int) sp.getStartPosition(dataPath.getCompilationUnit(), tree);
int end = (int) sp.getEndPosition(dataPath.getCompilationUnit(), tree);
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE,
text.substring(start, end));
if (start != (-1) || end != (-1)) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE,
text.substring(start, end));
}
}
return super.scan(tree, p);
}

View file

@ -2,13 +2,13 @@
- compiler.note.proc.messager: o instanceof String s
- compiler.note.proc.messager: o
- compiler.note.proc.messager: String s
- compiler.note.proc.messager: String s
- compiler.note.proc.messager: String
- compiler.note.proc.messager: (o instanceof java.lang.String s)
- compiler.note.proc.messager: o instanceof java.lang.String s
- compiler.note.proc.messager: o
- compiler.note.proc.messager: java.lang.String s
- compiler.note.proc.messager: java.lang.String s
- compiler.note.proc.messager: java.lang.String
- compiler.note.proc.messager: java.lang
- compiler.note.proc.messager: java
- compiler.note.preview.filename: PatternMatchPosTestData.java
- compiler.note.preview.recompile
- compiler.note.proc.messager: java

View file

@ -25,8 +25,8 @@
* @test
* @bug 8231827
* @summary Basic pattern test
* @compile --enable-preview -source ${jdk.version} PatternTypeTest2.java
* @run main/othervm --enable-preview PatternTypeTest2
* @compile PatternTypeTest2.java
* @run main PatternTypeTest2
*/
public class PatternTypeTest2 {

View file

@ -1,16 +0,0 @@
/*
* @test /nodynamiccopyright/
* @bug 8231827
* @summary Ensure that in type test patterns, the predicate is not trivially provable false.
* @compile/fail/ref=PatternVariablesAreFinal.out -XDrawDiagnostics --enable-preview -source ${jdk.version} PatternVariablesAreFinal.java
*/
public class PatternVariablesAreFinal {
public static void main(String[] args) {
Object o = 32;
if (o instanceof String s) {
s = "hello again";
System.out.println(s);
}
System.out.println("test complete");
}
}

View file

@ -1,4 +0,0 @@
PatternVariablesAreFinal.java:11:13: compiler.err.pattern.binding.may.not.be.assigned: s
- compiler.note.preview.filename: PatternVariablesAreFinal.java
- compiler.note.preview.recompile
1 error

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, 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
@ -21,15 +21,24 @@
* questions.
*/
// key: compiler.err.pattern.binding.may.not.be.assigned
// key: compiler.note.preview.filename
// key: compiler.note.preview.recompile
// options: --enable-preview -source ${jdk.version}
class ResourceMayNotBeAssigned {
void m(Object o) {
/*
* @test
* @bug 8231827
* @summary Pattern variables are non-final.
* @compile/fail/ref=PatternVariablesAreNonFinal.out -XDrawDiagnostics PatternVariablesAreNonFinal.java
*/
public class PatternVariablesAreNonFinal {
public static void main(String[] args) {
Object o = 32;
if (o instanceof String s) {
s = "";
s = "hello again";
new Runnable() {
@Override
public void run() {
System.err.println(s);
}
};
}
System.out.println("test complete");
}
}

View file

@ -0,0 +1,2 @@
PatternVariablesAreNonFinal.java:38:40: compiler.err.cant.ref.non.effectively.final.var: s, (compiler.misc.inner.cls)
1 error

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2020, 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
@ -24,11 +24,11 @@
/*
* @test
* @bug 8231827
* @summary Pattern variables are final so should be allowed to be referenced in an inner class
* @compile --enable-preview -source ${jdk.version} PatternVariablesAreFinal2.java
* @run main/othervm --enable-preview PatternVariablesAreFinal2
* @summary Pattern variables can be effectivelly final so should be allowed to be referenced in an inner class
* @compile PatternVariablesAreNonFinal2.java
* @run main PatternVariablesAreNonFinal2
*/
public class PatternVariablesAreFinal2 {
public class PatternVariablesAreNonFinal2 {
public static void main(String[] args) {
Object o = "42";
if (o instanceof String s) {
@ -36,5 +36,9 @@ public class PatternVariablesAreFinal2 {
void run() { System.err.println(s); }
}.run();
}
if (o instanceof String s) {
s = "hello again";
System.out.println(s);
}
}
}

View file

@ -105,7 +105,7 @@ public class PatternsSimpleVisitorTest {
StringWriter out = new StringWriter();
JavacTask ct = (JavacTask) tool.getTask(out, null, noErrors,
List.of("--enable-preview", "-source", Integer.toString(Runtime.version().feature())), null,
null, null,
Arrays.asList(new MyFileObject(code)));
return ct.parse().iterator().next();
}

View file

@ -2,7 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8231827
* @summary Verify behavior w.r.t. non-reifiable types and type test patterns in instanceof
* @compile/fail/ref=Reifiable.out --enable-preview -source ${jdk.version} -XDrawDiagnostics Reifiable.java
* @compile/fail/ref=Reifiable.out -XDrawDiagnostics Reifiable.java
*/
public class Reifiable implements ReifiableI {

View file

@ -2,6 +2,4 @@ Reifiable.java:10:16: compiler.err.instanceof.reifiable.not.safe: java.lang.Obje
Reifiable.java:12:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Reifiable.List<java.lang.String>, Reifiable.ListImpl<Reifiable>)
Reifiable.java:13:39: compiler.err.not.within.bounds: java.lang.String, T
Reifiable.java:14:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: Reifiable.List<Reifiable>, Reifiable.Unrelated<Reifiable>)
- compiler.note.preview.filename: Reifiable.java
- compiler.note.preview.recompile
4 errors

View file

@ -1,7 +1,5 @@
ReifiableOld.java:12:37: compiler.err.illegal.generic.type.for.instof
ReifiableOld.java:13:38: compiler.err.illegal.generic.type.for.instof
ReifiableOld.java:14:38: compiler.err.illegal.generic.type.for.instof
ReifiableOld.java:15:38: compiler.err.illegal.generic.type.for.instof
ReifiableOld.java:15:39: compiler.err.not.within.bounds: java.lang.String, T
ReifiableOld.java:16:39: compiler.err.illegal.generic.type.for.instof
6 errors
ReifiableOld.java:11:18: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.reifiable.types.instanceof), 15, 16
ReifiableOld.java:13:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: ReifiableOld.List<java.lang.String>, ReifiableOld.ListImpl<ReifiableOld>)
ReifiableOld.java:14:39: compiler.err.not.within.bounds: java.lang.String, T
ReifiableOld.java:15:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: ReifiableOld.List<ReifiableOld>, ReifiableOld.Unrelated<ReifiableOld>)
4 errors

View file

@ -2,9 +2,8 @@
* @test /nodynamiccopyright/
* @bug 8231827
* @summary Verify behavior w.r.t. non-reifiable types in instanceof
* @compile/fail/ref=ReifiableOld-old.out -source 13 -Xlint:-options -XDrawDiagnostics ReifiableOld.java
* @compile/fail/ref=ReifiableOld-old.out -source ${jdk.version} -XDrawDiagnostics ReifiableOld.java
* @compile/fail/ref=ReifiableOld.out --enable-preview -source ${jdk.version} -XDrawDiagnostics ReifiableOld.java
* @compile/fail/ref=ReifiableOld-old.out -source 15 -Xlint:-options -XDrawDiagnostics ReifiableOld.java
* @compile/fail/ref=ReifiableOld.out -XDrawDiagnostics ReifiableOld.java
*/
public class ReifiableOld implements ReifiableOldI {

View file

@ -1,7 +1,5 @@
ReifiableOld.java:12:16: compiler.err.instanceof.reifiable.not.safe: java.lang.Object, ReifiableOld.ListImpl<ReifiableOld>
ReifiableOld.java:14:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: ReifiableOld.List<java.lang.String>, ReifiableOld.ListImpl<ReifiableOld>)
ReifiableOld.java:15:39: compiler.err.not.within.bounds: java.lang.String, T
ReifiableOld.java:16:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: ReifiableOld.List<ReifiableOld>, ReifiableOld.Unrelated<ReifiableOld>)
- compiler.note.preview.filename: ReifiableOld.java
- compiler.note.preview.recompile
ReifiableOld.java:11:16: compiler.err.instanceof.reifiable.not.safe: java.lang.Object, ReifiableOld.ListImpl<ReifiableOld>
ReifiableOld.java:13:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: ReifiableOld.List<java.lang.String>, ReifiableOld.ListImpl<ReifiableOld>)
ReifiableOld.java:14:39: compiler.err.not.within.bounds: java.lang.String, T
ReifiableOld.java:15:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: ReifiableOld.List<ReifiableOld>, ReifiableOld.Unrelated<ReifiableOld>)
4 errors

View file

@ -2,7 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8187429 8231827
* @summary Missing unchecked conversion warning
* @compile/fail/ref=UncheckedWarningOnMatchesTest.out -Xlint:unchecked -Werror -XDrawDiagnostics --enable-preview -source ${jdk.version} UncheckedWarningOnMatchesTest.java
* @compile/fail/ref=UncheckedWarningOnMatchesTest.out -Xlint:unchecked -Werror -XDrawDiagnostics UncheckedWarningOnMatchesTest.java
*/
import java.util.ArrayList;

View file

@ -1,4 +1,2 @@
UncheckedWarningOnMatchesTest.java:14:13: compiler.err.instanceof.reifiable.not.safe: java.lang.Object, java.util.ArrayList<java.lang.Integer>
- compiler.note.preview.filename: UncheckedWarningOnMatchesTest.java
- compiler.note.preview.recompile
1 error

View file

@ -98,10 +98,7 @@ public class ScopeTest extends JavacTemplateTestBase {
}
private void assertOK(String block) {
String sourceVersion = Integer.toString(Runtime.version().feature());
reset();
addCompileOptions("--enable-preview", "-source", sourceVersion);
program(block);
try {
compile();
@ -113,10 +110,7 @@ public class ScopeTest extends JavacTemplateTestBase {
}
private void assertFail(String expectedDiag, String block) {
String sourceVersion = Integer.toString(Runtime.version().feature());
reset();
addCompileOptions("--enable-preview", "-source", sourceVersion);
program(block);
try {
compile();

View file

@ -105,20 +105,20 @@ public class TestBindingVariable extends JavacTestingAbstractProcessor implement
}
@Override
public Void visitBindingPattern(BindingPatternTree node, Void p) {
handleCurrentTreeAsBindingVar();
handleTreeAsBindingVar(new TreePath(getCurrentPath(), node.getVariable()));
return super.visitBindingPattern(node, p);
}
@Override
public Void visitIdentifier(IdentifierTree node, Void p) {
if (node.getName().contentEquals("bindingVar")) {
handleCurrentTreeAsBindingVar();
handleTreeAsBindingVar(getCurrentPath());
}
return super.visitIdentifier(node, p);
}
private void handleCurrentTreeAsBindingVar() {
Element element = trees.getElement(getCurrentPath());
private void handleTreeAsBindingVar(TreePath tp) {
Element element = trees.getElement(tp);
System.out.println("Name: " + element.getSimpleName() +
"\tKind: " + element.getKind());