Skip to content

fix(ksp): preserve generic type args for suspend functions returning non-generic typealiases + fix server leak in tests - #12708

Draft
graemerocher with Copilot wants to merge 4 commits into
5.1.xfrom
copilot/fix-comments-in-review-thread
Draft

fix(ksp): preserve generic type args for suspend functions returning non-generic typealiases + fix server leak in tests#12708
graemerocher with Copilot wants to merge 4 commits into
5.1.xfrom
copilot/fix-comments-in-review-thread

Conversation

Copilot AI commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

KSP was losing concrete type arguments when a suspend function returned a non-generic typealias (e.g. typealias BarList = List<Bar>). Because the alias has no typeParameters, KSType.arguments was empty, causing Argument.of(List, "T") with a literal "T" instead of the resolved Bar — resulting in a ClassCastException at runtime.

Changes

  • AbstractKotlinElement.kt: When resolving type arguments, detect a non-generic KSTypeAlias (one with no typeParameters) and expand to its underlying type before iterating arguments. This recovers the concrete type parameters (e.g. Bar) that would otherwise be invisible.

  • SuspendClient.kt / SuspendClientController.kt: Add typealias BarList = List<Bar> and a /bars endpoint returning List<Bar> to exercise the fix.

  • SuspendClientSpec.kt: Add regression test testSuspendClientReturnsTypealiasToList that calls getBars(): BarList and asserts the response is correctly deserialized. Additionally, wrap all tests in use { } blocks so the EmbeddedServer is always stopped after each test, preventing port/thread accumulation across the test JVM.

// Before — typealias return type loses its concrete argument
typealias BarList = List<Bar>

@Get("/bars")
suspend fun getBars(): BarList  // would fail with ClassCastException

// After — underlying type is resolved, Bar is correctly substituted

Copilot AI changed the title [WIP] Fix code for comments in review thread fix(ksp): preserve generic type args for suspend functions returning non-generic typealiases + fix server leak in tests Jun 5, 2026
Copilot AI requested a review from graemerocher June 5, 2026 18:36
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

Successfully merging this pull request may close these issues.

3 participants