openrewrite / rewrite-kotlin

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

Java classes may contain equivalent Kotlin types. #513

Open traceyyoshima opened 6 months ago

traceyyoshima commented 6 months ago
import java.lang.StringBuilder
class Test {
    fun method() {
        val sb = StringBuilder()
        sb.trimToSize()
    }
}

sb.trimToSize() should return a java.lang.void, but produces a kotlin.Unit. The void return type is represented by a kotlin.Unit in the FIR.

knutwannheden commented 6 months ago

I think this is still an "unsolved" problem. Also where the Java parser would produce primitive types or wrapper types in the type attribution, we for Kotlin have the corresponding Kotlin types. I am still unsure what we should do about that.

traceyyoshima commented 6 months ago

I think this is still an "unsolved" problem. Also where the Java parser would produce primitive types or wrapper types in the type attribution, we for Kotlin have the corresponding Kotlin types. I am still unsure what we should do about that.

I agree; I'm unsure why this happens since Java types like java.lang.void will appear on some Java classes and will be replaced in others. I checked the IR for this case; the return type was kotlin.Unit, too. I don't know of any meaningful impacts where Kotlin types like Int, Unit, etc. exist in place of Java types will have unless someone is searching for a use of an API from their Java code in their Kotlin code.