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

[KSP2] Resolver#overrides() gives incorrect result when method isn't accessible. #2254

Closed
bcorso opened this issue Dec 11, 2024 · 2 comments · Fixed by #2295
Closed

[KSP2] Resolver#overrides() gives incorrect result when method isn't accessible. #2254

bcorso opened this issue Dec 11, 2024 · 2 comments · Fixed by #2295
Milestone

Comments

@bcorso
Copy link

bcorso commented Dec 11, 2024

Consider the following two classes:

package a;
public class A {
  void method() { ... }
} 

package c;
public class C extends A {
  void method() { ... }
}

When using Resolver#overrides(methodC, methodA) we get different results in KSP1 and KSP2:

  • KSP1: Resolver#overrides(methodC, methodA) == false
  • KSP2: Resolver#overrides(methodC, methodA) == true

I think KSP2's result is wrong in this case because A#method() is not visible from class B, so rather than an override it's more like shadowing.

@bcorso
Copy link
Author

bcorso commented Dec 11, 2024

The jvm spec seems to also suggest this (https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.5):

An instance method mC declared in class C overrides another instance method mA declared in class A iff either mC is the same as mA, or all of the following are true:

  • C is a subclass of A.
  • mC has the same name and descriptor as mA.
  • mC is not marked ACC_PRIVATE.
  • One of the following is true:
    • mA is marked ACC_PUBLIC; or is marked ACC_PROTECTED; or is marked neither ACC_PUBLIC nor ACC_PROTECTED nor ACC_PRIVATE and A belongs to the same run-time package as C.
    • mC overrides a method m' (m' distinct from mC and mA) such that m' overrides mA.

In particular, the bolded bullet point above is false in the example mentioned in #2254 (comment), so I think Resolver#overrides(methodC, methodA) should also give false.

@bcorso bcorso changed the title Resolver#overrides() gives incorrect result when method isn't accessible. [KSP2] Resolver#overrides() gives incorrect result when method isn't accessible. Dec 11, 2024
@bcorso
Copy link
Author

bcorso commented Jan 14, 2025

(I also just realized I filed something very similar for KSP1 #1279)

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.

2 participants