Git Product home page Git Product logo

Comments (5)

yigit avatar yigit commented on May 7, 2024

Here is the repro I've tried.

import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.SourceFile
import com.tschuchort.compiletesting.symbolProcessors
import org.jetbrains.kotlin.ksp.getDeclaredFunctions
import org.jetbrains.kotlin.ksp.processing.CodeGenerator
import org.jetbrains.kotlin.ksp.processing.Resolver
import org.jetbrains.kotlin.ksp.processing.SymbolProcessor
import org.junit.Test

class ReturnTypeBug {
    class ReturnTypeBug_Processor() : SymbolProcessor {
        override fun finish() {

        }

        override fun init(options: Map<String, String>, kotlinVersion: KotlinVersion, codeGenerator: CodeGenerator) {

        }

        override fun process(resolver: Resolver) {
            val books = resolver.getClassDeclarationByName(
                resolver.getKSNameFromString("Books")
            ) ?: error("")
            val subject = books.getDeclaredFunctions().first {
                it.simpleName.asString() == "getDefaultBook"
            }
            val resolved = subject.returnType?.resolve()
            check(resolved?.toString() == "Book")
        }
    }

    @Test
    fun repro() {
        val annotation = SourceFile.java("TestTarget.java", """
            import java.lang.annotation.ElementType;
            import java.lang.annotation.Target;
            
            @Target({ElementType.METHOD})
            public @interface TestTarget {
            }
        """.trimIndent())
        val book = SourceFile.kotlin("Book.kt", """
            data class Book(val name:String)
        """.trimIndent())
        val books = SourceFile.kotlin("Books.kt", """
            interface Books {
                @TestTarget
                fun getDefaultBook() = getBook("default")
                fun getBook(name : String) : Book
            }
        """.trimIndent())
        val result = KotlinCompilation().apply {
            sources = listOf(book, books, annotation)
            symbolProcessors(ReturnTypeBug_Processor::class.java)
        }.compile()
        check(result.exitCode == KotlinCompilation.ExitCode.OK)
    }
}

from ksp.

neetopia avatar neetopia commented on May 7, 2024

Caused by: java.lang.AssertionError: Rewrite at slice ANNOTATION key: ANNOTATION_ENTRY

Found this pretty interesting log in stacktrace, I recall seeing this before.

cc @ting-yuan

from ksp.

ting-yuan avatar ting-yuan commented on May 7, 2024

There are two issues here:

  1. The AssertionError hides the underlying issue. It was raised when collecting the information about the location to be reported.
  2. The hidden, underlying issue which triggers the error report.

from ksp.

ting-yuan avatar ting-yuan commented on May 7, 2024

@yigit I've tried but still unable to reproduce, even with the first KSP release. Because there have been quite a few bug fixes since then, I'm wondering if the issue has gone away already. Would you mind to try again to see if it is still there in your working environment?

from ksp.

ting-yuan avatar ting-yuan commented on May 7, 2024

Closing as it seems to be not reproducible anymore.

from ksp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.