RFR: 8260566: Pattern type X is a subtype of expression type Y message is incorrect

Tagir F.Valeev tvaleev at openjdk.java.net
Fri Jan 29 12:02:40 UTC 2021


On Fri, 29 Jan 2021 11:20:06 GMT, Guoxiong Li <github.com+13688759+lgxbslgx at openjdk.org> wrote:

> Hi all,
> 
> The order of the arguments is wrong when using method `Errors.InstanceofPatternNoSubtype`.
> 
> This patch fixes it and revises the corresponding tests.
> Thank you for taking the time to review.
> And it may be good to fix JDK16 as well.
> 
> Best Regards.
> -- xiong

The fix doesn't seem correct to me. Consider the code in the ticket:

public class Test {
  void test(String s) {
    if(s instanceof Object obj) {}
  }
}

The previous message was:
Test.java:3: error: pattern type Object is a subtype of expression type String
    if(s instanceof Object obj) {}
It was incorrect because Object is not a subtype of String

After applying this fix, the message will be
Test.java:3: error: pattern type String is a subtype of expression type Object
    if(s instanceof Object obj) {}
It's also incorrect because String is not a pattern type, and Object is not an expression type. A correct message would be
Test.java:3: error: expression type String is a subtype of pattern type Object
or
Test.java:3: error: pattern type Object is a supertype of expression type String

-------------

PR: https://git.openjdk.java.net/jdk/pull/2311


More information about the compiler-dev mailing list