<div dir="ltr">Hi,<br><br>Chris Povirk and I were trying to understand why examples like the following are rejected:<br><br>sealed interface A<T> {<br>  enum B implements A<String> {<br>    C;<br>  }<br><br>  static void d(A<?> a) {<br>    switch (a) {<br>      case B.C:<br>    }<br>  }<br>}<br><br>A.java:8: error: incompatible types: B cannot be converted to A<CAP#1><br>      case B.C:<br>            ^<br>  where CAP#1 is a fresh type-variable:<br>    CAP#1 extends Object from capture of ?<br><br>I think this is a consequence of JLS 6.5.6.1, which says that the type of the switch selector expression is subject to capture conversion, and then the captured type is not convertible.<br><br>In the implementation, this is happening here [1], where attribExpr uses KindSelector.VAL, which causes the capture to happen.<br><br>Has consideration been given to treating selector expressions differently, to avoid the capture conversion, and allow examples like this to compile? I couldn't find test coverage for this specific combination of features, which made me wonder if this was a corner case that hadn't been explored, rather than something that had definitely been ruled out.<br><br>Liam<br><br>[1] <a href="https://github.com/openjdk/jdk/blob/a224f12cb701b45df4706a403a05c66de2d623af/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java#L1702">https://github.com/openjdk/jdk/blob/a224f12cb701b45df4706a403a05c66de2d623af/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java#L1702</a><br></div>