8000 Fix parent of Java method overriding Kotlin property by KlyneChrysler · Pull Request #3289 · google/ksp · GitHub
[go: up one dir, main page]

Skip to content

Fix parent of Java method overriding Kotlin property - #3289

Open
KlyneChrysler wants to merge 2 commits into
google:mainfrom
KlyneChrysler:klyne/2498-java-method-parent
Open

KlyneChrysler wants to merge 2 commits into
google:mainfrom
KlyneChrysler:klyne/2498-java-method-parent

Conversation

@KlyneChrysler
Copy link
Copy Markdown
Contributor

Goal

Fixes #2498.

parent/parentDeclaration of a Java method that overrides a Kotlin property returned the Kotlin property instead of the Java class declaring the method.

Summary

  • Override parent for Analysis API synthetic Java property accessors so it returns the declaring class.
  • Keep origin as SYNTHETIC for those accessors.
  • Resolve overridees and overrides() checks through the containing property symbol.
  • Enable the two regression tests that documented the bug.

Design decisions

  • The Analysis API models these methods as KaFirSyntheticPropertyGetterSymbol with KaSymbolOrigin.JAVA_SYNTHETIC_PROPERTY; their containingSymbol is the synthetic property. That relationship is kept for override resolution, but parent now exposes the class because the declaration is a Java method.
  • ResolverAAImpl.overrides previously cast parent to KSPropertyDeclarationImpl, which would throw after the parent fix. It now uses containingSymbol instead.

Test plan

  • ./gradlew :kotlin-analysis-api:test (AA/PSI and new-features suites, 620 tests)

A Java method overriding a Kotlin property is modeled by the Analysis API as a synthetic property accessor whose containing symbol is the property. Return the declaring class as its parent while keeping the declaration synthetic, and resolve the overridden property through the containing symbol so override checks keep working.

Fixes google#2498
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.

[KSP2] Incorrect parentDeclaration for Java method inheriting a Kotlin property

1 participant

0