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
- revert kotlinPoet bump due to https://github.com/square/kotlinpoet/issues/1513 — committed to wowselim/eventbus-service by wowselim a year ago
- bump kotlin from 1.8.10 to 1.8.20 (#162) * Bump org.jetbrains.kotlin:kotlin-gradle-plugin from 1.8.10 to 1.8.20 Bumps [org.jetbrains.kotlin:kotlin-gradle-plugin](https://github.com/JetBrains/kotli... — committed to wowselim/eventbus-service by dependabot[bot] a year ago
- KSType.toTypeName fixed to work with aliased types resolves #1513 — committed to Squiry/kotlinpoet by Squiry a year ago
- KSType.toTypeName fixed to work with aliased types (#1534) * KSType.toTypeName fixed to work with aliased types resolves #1513 * test fixed * imports fixed * test case * import fix ... — committed to square/kotlinpoet by Squiry a year ago
Confirmed!
If you have a fix, can you submit a fix + tests as a PR?