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 Expressions] Poor quality diagnostics #3289

Open
srikanth-sankaran opened this issue Nov 12, 2024 · 1 comment
Open

[Switch Expressions] Poor quality diagnostics #3289

srikanth-sankaran opened this issue Nov 12, 2024 · 1 comment
Assignees

Comments

@srikanth-sankaran
Copy link
Contributor

srikanth-sankaran commented Nov 12, 2024

This program generates two errors:

  • Syntax error, insert ";" to complete LocalVariableDeclarationStatement
  • Syntax error on token "yield", AssignmentOperator expected after this token
public class X {
	public static void main(String[] args) {
		Object x = "Hello";
		String j = switch (x) {
		case String s : yield "String";
		default : { System.out.println();
			yield "Default";
		}
		}
	}
}

The second one is not helpful and head scratch inducing.

(2) This program generates: C cannot be resolved or is not a field which is not quite the case even though the error is valid.

public class X {
	enum E1 {
		A;
	}
	
	enum E2 {
		B;
	}
	
	public static final int C = 42;
	
	public static void main(String[] args) {
	
	}
	void foo(E1 e1) {
		switch (e1) {
		case A :
		case C : 	
		}
		
		System.out.println(C);
	}
}

@srikanth-sankaran srikanth-sankaran self-assigned this Nov 12, 2024
@srikanth-sankaran
Copy link
Contributor Author

jaavc simply says "X.java:9: error: ';' expected"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant