openrewrite / rewrite-kotlin

Work-in-progress implementation of Kotlin language support for OpenRewrite.
Apache License 2.0
38 stars 11 forks source link

Type attribution issue: missing types on Annotations of assignment operations. #511

Open traceyyoshima opened 6 months ago

traceyyoshima commented 6 months ago

Annotations on expressions += and -= will not contain an associated FIR element. The issue is caused by the compiler and is fixed in 1.9.20.

https://youtrack.jetbrains.com/issue/KT-62473

nmck257 commented 6 months ago

Hey @traceyyoshima - this might be a separate issue, but I'm seeing missing types on a variety of annotation usages (in 1.8.1):

All these fail for me:

@Test
void fmtConstructorParamAnnotation() {
    rewriteRun(
            spec -> spec.recipe(new FindMissingTypes()).parser(KotlinParser.builder().logCompilationWarningsAndErrors(true)),
            kotlin("""
                    import org.openrewrite.internal.lang.NonNull

                    class Foo(
                        @NonNull val x: String
                    )
                    """
            ));
}

@Test
void fmtMethodParamAnnotation() {
    rewriteRun(
            spec -> spec.recipe(new FindMissingTypes()).parser(KotlinParser.builder().logCompilationWarningsAndErrors(true)),
            kotlin("""
                    import org.openrewrite.internal.lang.NonNull

                    class Foo {
                        fun foo(@NonNull x: String) = ""
                    }
                    """
            ));
}

@Test
void fmtClassAnnotation() {
    rewriteRun(
            spec -> spec.recipe(new FindMissingTypes()).parser(KotlinParser.builder().logCompilationWarningsAndErrors(true)),
            kotlin("""
                    import org.openrewrite.internal.lang.NonNull

                    @NonNull
                    class Foo
                    """
            ));
}