Bug 575737 - [17] Mismatch in error reported by ecj and javac with "illegal fall-through from a pattern"
Summary: [17] Mismatch in error reported by ecj and javac with "illegal fall-through f...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.21   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-01 04:03 EDT by Sravan Kumar Lakkimsetti CLA
Modified: 2024-04-26 06:36 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sravan Kumar Lakkimsetti CLA 2021-09-01 04:03:32 EDT
For the given code
public class X {
	private static void foo(Object o) {
	   switch (o.hashCode()) {
	     case Integer t:
	     default : System.out.println("Object");
	   }
	}
 
	public static void main(String[] args) {
		foo("Hello World");
	}
}

ecj reports error on converting int to Integer. Javac reports error in default with "illegal fall-through from a pattern"
Comment 1 Fred Bricon CLA 2021-09-10 04:35:52 EDT
Found another mismatch in switch handling. The following compiles fine with ECJ 
```
public class App {
    public static void main(String[] args) {
        var foo = switch (get()) {
            case null -> "null value";
            case default -> "default value";
        };
        System.out.println(foo);
    }

    private static Object get() {
        return null;
    }
}
```

But `javac App.java` fails to compile
```
❯ java -version
openjdk version "17-panama" 2021-09-14
OpenJDK Runtime Environment (build 17-panama+3-167)
OpenJDK 64-Bit Server VM (build 17-panama+3-167, mixed mode, sharing)
❯ javac App.java
App.java:5: error: illegal start of expression
            case default -> "default value";
```

Tested with https://download.eclipse.org/eclipse/updates/4.21-P-builds/P20210907-0320 in jdt.ls (https://github.com/eclipse/eclipse.jdt.ls/pull/1871/files#diff-f15305031e24556c35cc42f0684bf5bbe9451e76b57735163e51652610367dfbR50)

Let me know if you prefer handling it in another bug.
Comment 2 Sravan Kumar Lakkimsetti CLA 2021-09-10 05:33:08 EDT
(In reply to Fred Bricon from comment #1)
> Found another mismatch in switch handling. The following compiles fine with
> ECJ 
> ```
> public class App {
>     public static void main(String[] args) {
>         var foo = switch (get()) {
>             case null -> "null value";
>             case default -> "default value";
>         };
>         System.out.println(foo);
>     }
> 
>     private static Object get() {
>         return null;
>     }
> }
> ```
> 
> But `javac App.java` fails to compile
> ```
> ❯ java -version
> openjdk version "17-panama" 2021-09-14
> OpenJDK Runtime Environment (build 17-panama+3-167)
> OpenJDK 64-Bit Server VM (build 17-panama+3-167, mixed mode, sharing)
> ❯ javac App.java
> App.java:5: error: illegal start of expression
>             case default -> "default value";
> ```
> 
> Tested with
> https://download.eclipse.org/eclipse/updates/4.21-P-builds/P20210907-0320 in
> jdt.ls
> (https://github.com/eclipse/eclipse.jdt.ls/pull/1871/files#diff-
> f15305031e24556c35cc42f0684bf5bbe9451e76b57735163e51652610367dfbR50)
> 
> Let me know if you prefer handling it in another bug.

Please raise another bug.
Comment 3 Fred Bricon CLA 2021-09-10 06:13:09 EDT
My bad, turns out sdkman offered my a really old version of JDK 17. With the latest build (OpenJDK 64-Bit Server VM (build 17+35-2724)), the behaviour is consistent between javac and ecj.
Comment 4 Eclipse Genie CLA 2023-09-05 13:39:30 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.