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

Aliased import ignored for nullable variants of that type #2020

Open
mcarleio opened this issue Nov 14, 2024 · 0 comments
Open

Aliased import ignored for nullable variants of that type #2020

mcarleio opened this issue Nov 14, 2024 · 0 comments
Labels

Comments

@mcarleio
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant