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

InstanceOfPatternMatch gives wrong type parameter #308

Open
nazoking opened this issue Jun 30, 2024 · 1 comment
Open

InstanceOfPatternMatch gives wrong type parameter #308

nazoking opened this issue Jun 30, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@nazoking
Copy link

What version of OpenRewrite are you using?

I am using

  • OpenRewrite v6.16.2
  • Maven/Gradle plugin v6.16.2
  • org.openrewrite.recipe:rewrite-migrate-java:2.18.1

How are you running OpenRewrite?

I am using the Gradle plugin, and my project is a multi module project.

initscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2" }
    }
    dependencies {
        classpath("org.openrewrite:plugin:6.16.2")
    }
}

rootProject {
    plugins.apply(org.openrewrite.gradle.RewritePlugin)
    dependencies {
        rewrite("org.openrewrite.recipe:rewrite-spring:latest.release")
        rewrite("org.openrewrite.recipe:rewrite-migrate-java:2.18.1")
    }

    afterEvaluate {
        if (repositories.isEmpty()) {
            repositories {
                mavenCentral()
            }
        }
    }
}

and run

./gradlew --init-script rewrite.gradle rewriteRun -Drewrite.activeRecipe=org.openrewrite.staticanalysis.InstanceOfPatternMatch

What is the smallest, simplest way to reproduce the problem?

A code snippet can be something simple like this.

        if(obj instanceof List) {
            test((List)list);
        }

     static public String test(List<String> list){

What did you expect to see?

        if(obj instanceof List list) {
            test(list);
        }

     static public String test(List<String> list){

What did you see instead?

        if(obj instanceof List<?> list) {
            test(list);
        }

     static public String test(List<String> list){

List<?> is not the same as List , this will result in a compilation error like this:

 error: incompatible types: List<CAP#1> cannot be converted to List<String>
            test(list));
            ^
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Object from capture of ?

Are you interested in contributing a fix to OpenRewrite?

Indicate if this is something you would like to work on, and how we can best support you in doing so.

@nazoking nazoking added the bug Something isn't working label Jun 30, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Jul 2, 2024
@timtebeek
Copy link
Contributor

Thanks for the detailed report once again @nazoking ! Indeed an issue with how we handle generics. Would you be willing to turn the above into a runnable unit test and start a draft PR as a step up to a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants