jdk-24/test/langtools/tools/javac/patterns/AnnotationErrors.java
Jan Lahoda eaa80ad08c 8300543: Compiler Implementation for Pattern Matching for switch
8300545: Compiler Implementation for Record Patterns

Co-authored-by: Aggelos Biboudis <abimpoudis@openjdk.org>
Reviewed-by: vromero, mcimadamore
2023-05-22 04:24:06 +00:00

43 lines
1.2 KiB
Java

/*
* @test /nodynamiccopyright/
* @bug 8300543
* @summary Verify error related to annotations and patterns
* @compile/fail/ref=AnnotationErrors.out -XDrawDiagnostics -XDshould-stop.at=FLOW AnnotationErrors.java
*/
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
public class AnnotationErrors {
private void test(Object o, G<String> g) {
boolean b1 = o instanceof @DA R(var s);
boolean b2 = o instanceof @DTA R(var s);
boolean b3 = o instanceof @TA R(var s);
boolean b5 = g instanceof G<@DTA String>(var s);
boolean b6 = g instanceof G<@TA String>(var s);
switch (o) {
case @DA R(var s) when b1 -> {}
case @DTA R(var s) when b1 -> {}
case @TA R(var s) when b1 -> {}
default -> {}
}
switch (g) {
case G<@DTA String>(var s) when b1 -> {}
case G<@TA String>(var s) when b1 -> {}
default -> {}
}
}
record R(String s) {}
record G<T>(T t) {}
@Target(ElementType.LOCAL_VARIABLE)
@interface DA {}
@Target({ElementType.TYPE_USE, ElementType.LOCAL_VARIABLE})
@interface DTA {}
@Target(ElementType.TYPE_USE)
@interface TA {}
}