named pattern variable in pattern list
Jan Lahoda
jan.lahoda at oracle.com
Wed Jan 29 07:44:54 UTC 2025
Hello Stephan,
I've filled:
https://bugs.openjdk.org/browse/JDK-8348928
Thanks for the report!
Jan
On 28. 01. 25 18:49, Stephan Herrmann wrote:
> Our tests reveal a difference between compilers regarding this program:
>
> public class X {
> record Point (int x, int y) {}
> static void foo(Object o) {
> switch (o) {
> case Integer _, Point(int x, int _), String _ :
> System.out.println("Integer");
> default:
> System.out.println("Object");
> }
> }
> public static void main(String [] args) {
> foo("");
> }
> }
>
> We expect an error to be raised against x in the record pattern,
> because it seems to violate this from JLS §14.11.1:
>
> "It is a compile-time error for a case label to have more than one
> case pattern and declare any pattern variables (other than those
> declared by a guard associated with the case label)."
>
> This program is accepted by javac. Am I right to assume that this is a
> bug in javac?
>
> thanks,
> Stephan
More information about the compiler-dev
mailing list