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

self referencing type parameters w/ more than 1 type parameter does not work #125

Closed
yigit opened this issue Jun 3, 2021 · 0 comments · Fixed by #151
Closed

self referencing type parameters w/ more than 1 type parameter does not work #125

yigit opened this issue Jun 3, 2021 · 0 comments · Fixed by #151

Comments

@yigit
Copy link

yigit commented Jun 3, 2021

For this input, moshi ksp fails to compile (cannot find R while trying to resolve T).

@JsonClass(generateAdapter = true)
  open class Node<T : Node<T, R>, R : Node<R, T>> {
    var t : T? = null
    var r : R? = null
  }

  @JsonClass(generateAdapter = true)
  class StringNodeNumberNode(
  ) : Node<StringNodeNumberNode, NumberStringNode>() {
    var text: String = ""
  }

  @JsonClass(generateAdapter = true)
  class NumberStringNode(
  ) : Node<NumberStringNode, StringNodeNumberNode>() {
    var number: Int = 0
  }

I tried to patch thee compiler by registering type vars before resolving them, seems to fix it but it is not a clean implementation:
yigit@7bf262e

Failing test case before the fix:
https://github.com/yigit/MoshiX/blob/self-referencing-types/moshi-ksp/tests/src/test/kotlin/dev/zacsweers/moshix/ksp/DualKotlinTest.kt#L365

ZacSweers added a commit that referenced this issue Aug 27, 2021
ZacSweers added a commit that referenced this issue Aug 27, 2021
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 a pull request may close this issue.

1 participant