Interesting switch pattern-matching snippets that don't compile but maybe should
David Alayachew
davidalayachew at gmail.com
Sun Jan 22 01:03:59 UTC 2023
Am I missing something? Your first example does not compile.
I pulled down the early access 32 build, and the first example that you
said compiles fine, doesn't.
Here is the link I downloaded from --
https://download.java.net/java/early_access/jdk20/32/GPL/openjdk-20-ea+32_windows-x64_bin.zip
Here is my java --version output.
openjdk 20-ea 2023-03-21
OpenJDK Runtime Environment (build 20-ea+32-2328)
OpenJDK 64-Bit Server VM (build 20-ea+32-2328, mixed mode, sharing)
And here is my javac --version output.
javac 20-ea
And then here is what happens when I try to compile your first example.
---------
PotentialJavaBugs\src\main\java\io\github\davidalayachew\ShouldThisCompile.java:7:
error: invalid permits clause
sealed interface Base<T> extends Uber<T> permits Foo, Bar, Other{}
^
(subclass Other<T> must extend sealed class)
where T is a type-variable:
T extends Object declared in record Other
PotentialJavaBugs\src\main\java\io\github\davidalayachew\ShouldThisCompile.java:10:
error: class is not allowed to extend sealed class: Uber (as it is not
listed in its permits clause)
record Other<T>() implements Uber<T>{}
^
PotentialJavaBugs\src\main\java\io\github\davidalayachew\ShouldThisCompile.java:25:
error: incompatible types: Base<Integer> cannot be converted to
Other<Integer>
case Other<Integer> o -> "Hello";
^
PotentialJavaBugs\src\main\java\io\github\davidalayachew\ShouldThisCompile.java:39:
error: incompatible types: Base<Integer> cannot be converted to
Other<Integer>
case Other<Integer> o -> "Hello";
^
PotentialJavaBugs\src\main\java\io\github\davidalayachew\ShouldThisCompile.java:45:
error: incompatible types: Base<Integer> cannot be converted to
Other<Integer>
case Other<Integer> o -> {
^
Note:
PotentialJavaBugs\src\main\java\io\github\davidalayachew\ShouldThisCompile.java
uses preview features of Java SE 20.
Note: Recompile with -Xlint:preview for details.
5 errors
-----------
Please let me know if I am missing something.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230121/0342b387/attachment.htm>
More information about the amber-dev
mailing list