kotlinpoet: KSType.toTypeName function returns ClassName for alias type instead of ParameterizedTypeName

Describe the bug I expect calling KSType.toTypeName() on a type like ArrayList<String> to return ParameterizedTypeName with rawType=kotlin.collections.List and typeArguments=[kotlin.String], but I get just raw ClassName(kotlin.collections.List) instead.

To Reproduce Just change this line to val parameterType = parameter.type.resolve().toTypeName(functionTypeParams).let { and smokeTest will fail with something like this:

value of:
    readText$default(...)
diff (-expected +actual):
    @@ -103,7 +103,7 @@
         nullableSetListMapArrayNullableIntWithDefault: Set<List<Map<String, Array<IntArray?>>>>?,
         aliasedName: TypeAliasName,
         genericAlias: GenericTypeAlias,
    -    parameterizedTypeAlias: ParameterizedTypeAlias<String>,
    +    parameterizedTypeAlias: ParameterizedTypeAlias,
         nestedArray: Array<Map<String, Any>>?,
       ): Unit {
       }
	at com.squareup.kotlinpoet.ksp.test.processor.TestProcessorTest.smokeTest(TestProcessorTest.kt:146)

Additional context Right now on a master branch KSType.toTypeName return non parameterized ClassName even for non aliased types and reproducer from above will break the with much more errors. This behaviour was changed in a #1321 and I don’t know if this was intended.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 19 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Confirmed!

If you have a fix, can you submit a fix + tests as a PR?