Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[switch][pattern] Scope of pattern binding extends illegally resulting in wrong diagnostic #1853

Closed
srikanth-sankaran opened this issue Jan 12, 2024 · 1 comment · Fixed by #1883
Assignees
Milestone

Comments

@srikanth-sankaran
Copy link
Contributor

srikanth-sankaran commented Jan 12, 2024

Consider the program:

public class X {
    public static void main(String[] args) {
		Object o = new Object();
		switch (o) {
		case String s :
			if (!(o instanceof String str))
				throw new RuntimeException();
		case null : 
			if (!(o instanceof String str))
				throw new RuntimeException();
		default:
                        System.out.println("Default");
		}
	}
}

ECJ rejects this with: Duplicate local variable str but that is wrong. Javac compiles the code and when run it prints "Default" as it should

@srikanth-sankaran srikanth-sankaran self-assigned this Jan 12, 2024
@srikanth-sankaran srikanth-sankaran added this to the 4.31 M2 milestone Jan 12, 2024
@srikanth-sankaran
Copy link
Contributor Author

See also https://bugs.eclipse.org/bugs/show_bug.cgi?id=577415 - related but different bug

srikanth-sankaran added a commit to srikanth-sankaran/eclipse.jdt.core that referenced this issue Jan 12, 2024
srikanth-sankaran added a commit to srikanth-sankaran/eclipse.jdt.core that referenced this issue Jan 17, 2024
srikanth-sankaran added a commit that referenced this issue Jan 18, 2024
*  Ensure pattern bindings don't transcend their proper scope 
* Fixes https://bugs.eclipse.org/bugs/show_bug.cgi?id=577415
* Fixes [switch][pattern] Scope of pattern binding extends illegally resulting in wrong diagnostic #1853
robstryker pushed a commit to robstryker/eclipse.jdt.core that referenced this issue Jul 18, 2024
…se-jdt#1883)

*  Ensure pattern bindings don't transcend their proper scope 
* Fixes https://bugs.eclipse.org/bugs/show_bug.cgi?id=577415
* Fixes [switch][pattern] Scope of pattern binding extends illegally resulting in wrong diagnostic eclipse-jdt#1853
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment