<div dir="ltr">Hi,<br><div><br></div><div>I had a question about a change that was made to instanceof patterns as part of JEP 440.</div><div><br></div><div>javac emits diagnostics for instanceof patterns where the expression type is a subtype of the pattern type in JDK 20, but the diagnostics were removed in 21 as part of the implementation of JEP 440.</div><div><br></div><div>The <a href="https://cr.openjdk.org/~gbierman/jep440%2B441/jep440%2B441-20230509/specs/patterns-switch-record-patterns-jls.html#jls-15.20">spec diff</a> for those changes removed language from 15.20 about</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">If the type of the RelationalExpression is a subtype of the type of the Pattern, then a compile-time error occurs.</blockquote><div><br></div><div>The implementation also updated test/langtools/tools/javac/patterns/NoSubtypeCheck.java to test for those diagnostics when --release 20 is passed.<br><br>So all of this seems deliberate and working as intended, I was just curious what the rationale for the change was. Does anyone remember the history or have pointers to discussions about it on list?</div><div><br></div><div>public class Z {<br>  class A {}<br>  class B extends A {}<br>  void f(B b) {<br>    if (b instanceof A a) {}<br>  }<br>}</div><div><br></div><div>Z.java:5: error: expression type Z.B is a subtype of pattern type Z.A<br>    if (b instanceof A a) {}<br>          ^</div></div>