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

[21][pattern switch] ParameterizedType in Exhaustive check not done. #587

Closed
Tracked by #891
mpalat opened this issue Dec 5, 2022 · 2 comments
Closed
Tracked by #891
Assignees
Milestone

Comments

@mpalat
Copy link
Contributor

mpalat commented Dec 5, 2022

Reproduced from https://bugs.eclipse.org/bugs/show_bug.cgi?id=579360

from Alexander Kriegisch - reproduced verbatim:
From bug 576746 comment 5

public class SwitchPatternPreview2OK {
sealed interface I permits A, B {}
final static class A implements I {}
final static class B implements I {}

static int testGenericSealedExhaustive(I i) {
return switch (i) {
// Exhaustive as no A case possible!
case B bi -> 42;
};
}
}


$ java -jar org.eclipse.jdt.core/target/org.eclipse.jdt.core-3.29.50-SNAPSHOT-batch-compiler.jar -18 --enable-preview ../AspectJ/tests/features199/java18/SwitchPatternPreview2OK.java
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true

  1. WARNING in C:\Users\alexa\Documents\java-src\AspectJ\tests\features199\java18\SwitchPatternPreview2OK.java (at line 2)
    sealed interface I permits A, B {}
    ^
    SwitchPatternPreview2OK.A is a raw type. References to generic type SwitchPatternPreview2OK.A should be parameterized

  1. WARNING in C:\Users\alexa\Documents\java-src\AspectJ\tests\features199\java18\SwitchPatternPreview2OK.java (at line 2)
    sealed interface I permits A, B {}
    ^
    SwitchPatternPreview2OK.B is a raw type. References to generic type SwitchPatternPreview2OK.B should be parameterized

  1. ERROR in C:\Users\alexa\Documents\java-src\AspectJ\tests\features199\java18\SwitchPatternPreview2OK.java (at line 7)
    return switch (i) {
    ^
    A switch expression should have a default case

  1. WARNING in C:\Users\alexa\Documents\java-src\AspectJ\tests\features199\java18\SwitchPatternPreview2OK.java (at line 8)
    // Exhaustive as no A case possible!
    case B bi -> 42;
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    You are using a preview language feature that may or may not be supported in a future release

4 problems (1 error, 3 warnings)


So it seems as if the improved exhaustiveness logic has not been implemented yet either.

@kriegaex
Copy link
Contributor

kriegaex commented Mar 28, 2023

@mpalat, @jarthana: I just re-tested this on JDK 20 and the current batch compiler after the Java 20 merge to the main branch. This issue is still unresolved. Javcac 20 compiles it fine, ECJ does not.

Again, the code I just compiled with both compilers:

/**
 * Inspired by examples in https://openjdk.org/jeps/427
 */
public class SwitchPatternPreview4OK {
  /**
   * According to an example from JEP 420, this should work with preview 2 (Java 18), and it does with Javac,
   * but not with ECJ for Java 18, 19 and 20.
   *
   * See:
   *   https://openjdk.java.net/jeps/420#2--Exhaustiveness-of-switch-expressions-and-statements
   *   https://bugs.eclipse.org/bugs/show_bug.cgi?id=579360
   *   https://github.com/eclipse-jdt/eclipse.jdt.core/issues/587
   *
   * TODO: reactivate when implemented or move to preview 5 with Java 21.
   */
  sealed interface I<T> permits D, E {}
  final static class D<X> implements I<String> {}
  final static class E<Y> implements I<Y> {}

  static int testGenericSealedExhaustive(I<Integer> i) {
    return switch (i) {
      // Exhaustive as no D case possible!
      case E<Integer> bi -> 42;
    };
  }
}

@iloveeclipse iloveeclipse modified the milestones: 4.28, 4.29 Jun 8, 2023
@mpalat mpalat changed the title [pattern switch] recursive exhaustiveness not determined [pattern switch] ParameterizedType in Exhaustive check not done. Aug 16, 2023
mpalat added a commit to mpalat/eclipse.jdt.core that referenced this issue Aug 16, 2023
@mpalat mpalat self-assigned this Aug 16, 2023
@mpalat mpalat modified the milestones: 4.29, BETA_JAVA21 Aug 16, 2023
@mpalat mpalat changed the title [pattern switch] ParameterizedType in Exhaustive check not done. [21][pattern switch] ParameterizedType in Exhaustive check not done. Aug 16, 2023
@mpalat
Copy link
Contributor Author

mpalat commented Aug 16, 2023

done

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

3 participants