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

KSType.toTypeName() is inaccurate when typealias are mixed. #1369

Closed
nazoking opened this issue Sep 17, 2022 · 4 comments
Closed

KSType.toTypeName() is inaccurate when typealias are mixed. #1369

nazoking opened this issue Sep 17, 2022 · 4 comments

Comments

@nazoking
Copy link

When a type aliased as a generic type has a type parameter, the result of method KSType.toTypeName() outputs an incorrect type name and type parameter.

The following pattern is as expected.

// on code,
typealias Alias2<X> = Map<X, Int>
lateinit var n3: Alias2<String>

// and in ksp processor,
resolver.getPropertyDeclarationByName("n2", true)!!.type.toTypeName().toString()
// expected:  `Alias2<String>`  , equals actual: `Alias2<String>` 

However, the next two patterns are incorrect

// on code,
typealias Alias = List<Int>
val n: List<Alias>

// and in ksp processor,
resolver.getPropertyDeclarationByName("n", true)!!.type.toTypeName().toString()
// expected:  `List<Alias>`   , but actual: `List<Alias<Int>>` 
// on code,
typealias Alias2<X> = Map<X, Int>
lateinit var n2: List<Alias2<String>>

// and in ksp processor,
resolver.getPropertyDeclarationByName("n2", true)!!.type.toTypeName().toString()
// expected:  `List<Alias2<String>>`   , but actual: `List<Alias2<String, Int>>` 
@nazoking nazoking changed the title Type.toTypeName() is inaccurate when typealias are mixed. KSType.toTypeName() is inaccurate when typealias are mixed. Sep 17, 2022
@ZacSweers
Copy link
Collaborator

What version are you using?

@nazoking
Copy link
Author

i'm using

  • kotlinpoet-ksp 1.20.0
  • com.google.devtools.ksp:symbol-processing 1.7.10-1.0.6
  • org.jetbrains.kotlin.jvm 1.7.10

@nazoking
Copy link
Author

oh..?

I just ran your test file with my test code and run it, I get different results than what you report above. ( The results were output as expected. )
I will look into this a little more. Please let me know if you can give me any hints.
My test environment is
jdk version is 14
gradle is 7.2.

@nazoking
Copy link
Author

ok.

The cause was found.
The problem I faced was one that was fixed by the pull request #1321 .
This fix has not yet been released and has not been incorporated in the version 1.20.0 I am testing.
I close this Issue.
I look forward to a release in the near future.
Thanks for a great library.

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

No branches or pull requests

2 participants