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

hasBackingField returns wrong value for companion properties #491

Closed
yigit opened this issue Jun 25, 2021 · 1 comment
Closed

hasBackingField returns wrong value for companion properties #491

yigit opened this issue Jun 25, 2021 · 1 comment
Assignees
Labels
bug Something isn't working P1 major features or blocking bugs
Milestone

Comments

@yigit
Copy link
Collaborator

yigit commented Jun 25, 2021

When a companion field is coming from a .class file, hasBackingField always returns false.

class MyClass {
  companion object {
    var prop:String = "" // returns true if in source, false if it already compiled
  }
}

repro
yigit@c26fd51

@ting-yuan ting-yuan added bug Something isn't working P1 major features or blocking bugs labels Jun 29, 2021
@ting-yuan ting-yuan added this to the 1.0.0 milestone Jun 29, 2021
copybara-service bot pushed a commit to androidx/androidx that referenced this issue Jul 7, 2021
This CL fixes a bug KSP abstraction where it would consider any property
as a field even when the property does not have a backing field.

Now instead, we properly exclude them from fields list.

We also had another small bug where we didn't create fields for
companion properties. KAPT does so now we do as well. For that, I've
changed the KSDeclaration isStatic helper to check for companion
objects. It is necessary as `isStatic` is used for overrides, asMemberOf
etc. (asMemberOf won't work between a class and its companion).

We've hit a bug in KSP where backing field value is wrong for static
companion fields in the classpath so that test path is excluded for now:
google/ksp#491

Also fixed the declared fields implementation in KSP to properly return
based on backing field.

Bug: 177660733
Test: XTypeElementTest
Change-Id: I978c285e5b720bd8cbabb4df563a85153cbb5918
@ting-yuan ting-yuan self-assigned this Jul 29, 2021
@ting-yuan
Copy link
Collaborator

Fixed in #565

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

No branches or pull requests

2 participants