-
Notifications
You must be signed in to change notification settings - Fork 306
Closed
Labels
Description
Describe the bug
An aliased import added via addAliasedImport is not used when e.g. function arguments or return types are a nullable version of that:
To Reproduce
package org.example
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.asTypeName
class PersonId
fun main() {
println(
FileSpec.builder("org.example", "SomeFile")
.addAliasedImport(PersonId::class, "PID")
.addFunction(
FunSpec.builder("pid")
.addParameter("pid", PersonId::class.asTypeName().copy(nullable = true))
.returns(PersonId::class.asTypeName().copy(nullable = true))
.addCode("return null")
.build()
)
.build()
)
}
Expected behavior
Use the import alias for nullable types:
package org.example
import org.example.PersonId as PID
public fun pid(pid: PID?): PID? = null
Actual behavior
Does not use the import alias for nullable types:
package org.example
import org.example.PersonId as PID
public fun pid(pid: org.example.PersonId?): org.example.PersonId? = null
Additional context
Used version 2.0.0 above.
Worked with version 1.16.0.
Broken since 1.17.0.