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

KSTypeParameter#bounds returns <ERROR TYPE> when the bounds is another type parameter #1250

Closed
bcorso opened this issue Dec 27, 2022 · 0 comments · Fixed by #1262
Closed
Assignees
Labels
bug Something isn't working P1 major features or blocking bugs
Milestone

Comments

@bcorso
Copy link

bcorso commented Dec 27, 2022

For example:

// MyClass.java
class MyClass {
  static <T1, T2 extends T1> T2 method(T1 input) {
    return null; 
  }
}

Now, say we try to inspect the bounds of the method return type, T2:

  val t2: KSType = method.returnType.resolve()
  val t2Declaration: KSTypeParameter = t2.declaration as KSTypeParameter
  val t2Bounds: List<KSType> = t2Declaration.bounds.map { it.resolve() }.toList()
  println("{DECLARATION: $t2Declaration, BOUNDS: $t2Bounds}")

This results in {DECLARATION: T2, BOUNDS: [<ERROR TYPE>]}

Interestingly, if we get the matching KSTypeParameter from the parent declaration's type parameters it contains the correct bounds, e.g.

  val t2: KSType = method.returnType.resolve()
  val t2Declaration: KSTypeParameter =
      t2.declaration.parentDeclaration.typeParameters
          .filter { it.name =(t2.declaration as KSTypeParameter).name }
          .single()
  val t2Bounds: List<KSType> = t2Declaration.bounds.map { it.resolve() }.toList()
  println("{DECLARATION: $t2Declaration, BOUNDS: $t2Bounds}")

This results in {DECLARATION: T2, BOUNDS: [(T1..T1?)]}

@ting-yuan ting-yuan added bug Something isn't working P1 major features or blocking bugs labels Dec 27, 2022
@ting-yuan ting-yuan added this to the 1.0.9 milestone Jan 5, 2023
neetopia added a commit to neetopia/ksp that referenced this issue Jan 11, 2023
fix type resolution for java type parameters.
fixes google#1250
neetopia added a commit to neetopia/ksp that referenced this issue Jan 11, 2023
fix type resolution for java type parameters.
fixes google#1250
neetopia added a commit that referenced this issue Jan 12, 2023
fix type resolution for java type parameters.
fixes #1250
github-actions bot pushed a commit that referenced this issue Jan 12, 2023
fix type resolution for java type parameters.
fixes #1250

(cherry picked from commit 402a62b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1 major features or blocking bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants