-
Notifications
You must be signed in to change notification settings - Fork 139
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
List of patterns in case statements #1742
Conversation
6bc645b
to
e9ab807
Compare
Seems like update: Ah I see, in d4e6217 Srikanth added one of the fixes that I included in this PR, so now it pops off more expressions than are on the stack. update: I have addressed this, it should be working now |
UPDATE: this test failure is related to an actual bug, I'll look into it
class SwitchCompletion {
public static void main(String... args) {
int i = 0;
switch (i) {
case fred().xyzabc: System.out.println();
}
}
MyObj fred() {
return new MyObj(0);
}
}
record MyObj(int myProp) {
public static final int xyzabc = 0;
} This is because you are not allowed to invoke and the test case seems to be about converting |
02a0ce7
to
bf4ca9b
Compare
@srikanth-sankaran @jarthana This PR is ready for review. The tests are passing. I still have to add code generation, but in order to test code generation, I will need #1517, since you need to use unnamed variables in order to use lists of Patterns in case statements. |
I'll take a look in a couple of days. Thanks |
In that case, let us focus and prioritize #1517 please. That PR needs to be rebased and updated and then I will help close it. |
bf4ca9b
to
d0c65d9
Compare
@datho7561 - I have made us joint owners of this. I would like to include this as part of the comprehensive cleaup to pattern code generation rather than rush through this. |
d0c65d9
to
8f9bd0a
Compare
that "4 new warnings" seem unrelated and should go away when you rebase on master |
org.eclipse.jdt.internal.compiler.codegen.CodeStream.addVisibleLocalVariable * Fixes eclipse-jdt#1889
Pattern.resumeVariables * Fixes eclipse-jdt#2019
pattern variable declaration * Fixes eclipse-jdt#2017
pattern applicability check * Fixes eclipse-jdt#2001
as unnecessary * Fixes eclipse-jdt#1999
for PatternInstanceofExpression * Fixes https://bugs.eclipse.org/bugs/show_bug.cgi?id=575070
I've been working on rebasing this PR. It seems many things are working properly. However, I've hit a roadblock when it comes to fallthrough with cases with pattern. I've figured out some hacks to get this working: public class Issue712_001 {
public static void main(String[] args) {
Object o = "Hello World";
foo(o);
}
public static void foo(Object o) {
switch (o) {
case String s:
System.out.println(s); // No break!
case R():
System.out.println("It's either an R or a string"); // Allowed
break;
default:
}
}
}
record R() {}
record S() {} However, then I ran into a public class fallthroughPattern {
public static void main(String... args) {
Object o = "";
switch (o) {
case String s:
System.out.println("this is the first outcome");
case R(String _):
System.out.println("this is the second outcome");
case R(Integer _):
System.out.println("this is the third outcome");
default:
System.out.println("this is the fourth outcome");
}
}
private static final record R<T>(T a) {}
} |
Thanks David. Note that Jay reported three problems of which fixes for only two are pushed to that PR. I am working on the other one which very likely is involved in the case you cite. I expect to push a fix before end of business Wednesday. Do you have a link for the javac defect you reported ?? |
Please pick up the latest from the cumulative pattern fixes PR. I fixed a few problems today. May be it will be of help in what issues you are facing |
Thank you!
I tried opening the bug right after I reported it, but I couldn't find it. I'll try again
I'll rebase against your PR today. I might as well push the somewhat working rebase as well. |
f60cfc9
to
eb6709c
Compare
- Multiple patterns are reported as an error unless all variables are unnamed - GuardedPattern now has a list of Patterns as a child, deprecate the methods that assume it has one - Modified tests to adapt to the parser not handling multiple guards in one case statement any more (this was never allowed, but now the error has changed) - Modify tests that allow variables after record patterns (this feature was removed before record patterns moved out of preview) - AST & generator changes Signed-off-by: David Thompson <[email protected]>
I still wasn't able to find the bug I submitted to javac regarding switch statements with patterns with fallthrough. Maybe I'll try submitting again? I think that I got all the tests working after rebasing on your latest change, just running locally to ensure nothing bad happened. |
eb6709c
to
588a3e3
Compare
Could you describe here what the defect is ? Sometimes there is a latency as I recall.
Excellent. I'll look into absorbing it into the cumulative fixes branch this week. Any case I would like to wrap up this work by end of Feb. |
Not being an expert in git/github, I wonder how I would see just the diffs wrt to https://github.com/srikanth-sankaran/eclipse.jdt.core/tree/patterns-accumulated-fixes branch head. Let me know if you think this is ready for me to start with the review and absorbing the changes |
I have picked up the changes from here and pushed them to #2011 - action can continue there. I am reviewing the changes and will push additional commits for any issues I find during review/testing. I may ask for help with some tasks - any additional commits can be against the srikanth-sankaran:patterns-accumulated-fixes branch |
Closes #1643
What it does
Parse case statements with multiple patterns, as per JEP 443.
How to test
Confirm the following code snippet compiles and executes as expected:
Confirm that errors are placed on
a
andb
in the following snippet:Author checklist