Git Product home page Git Product logo

Comments (9)

yigit avatar yigit commented on May 7, 2024

Seems like it has nothing to do w/ Any or equals.
If the overriding method has protected, it fails.

e.g. with the following code:

        val source1 = SourceFile.java("TestClass.java", """
            public class TestClass extends Base {
                protected void test() {}
            }
        """.trimIndent())
        val base = SourceFile.java("Base.java", """
            public class BaseClass {
                protected void test() {}
            }
        """.trimIndent())

Checking TestClass.test overrides BaseClass.test also throws.
If I change the protected in TestClass to public, it works fine.

from ksp.

yigit avatar yigit commented on May 7, 2024

some more information.

Seems like it is an issue specific to KSFunctionDeclarationDescriptorImpl while it works fine with KSFunctionDeclarationJavaImpl.

More specifically, if I get a class via resolver.getClassDeclarationByName, it returns KSClassDeclarationDescriptorImpl whereas if i get it via a kotlin subclass (symbol.superTypes.first().resolve()?.declaration), then it returns KSClassDeclarationJavaImpl and it works properly.

So seems like an issue in resolver.
I think the fix is straightforward to extend the check to handle protected but i'm not sure if that'll just hide another bug.
Why does the resolver return two different implementations based on the call site?

from ksp.

yigit avatar yigit commented on May 7, 2024

I tried extending the javaModifiers test and the value returned from java are a bit different:

C: PUBLIC ABSTRACT
staticStr: PRIVATE
s1: FINAL JAVA_TRANSIENT
i1: PROTECTED JAVA_STATIC JAVA_VOLATILE
intFun: JAVA_SYNCHRONIZED JAVA_DEFAULT
foo: ABSTRACT JAVA_STRICT
abstractVoidMethod: PROTECTED

If I visit the declaration by directly getting it via:

resolver.getClassDeclarationByName(
      resolver.getKSNameFromString("C")
)

it prints:

C: ABSTRACT PUBLIC
abstractVoidMethod: OPEN PROTECTED
hashCode: OPEN PUBLIC OVERRIDE
equals: OPEN PUBLIC OPERATOR OVERRIDE
toString: OPEN PUBLIC OVERRIDE
intFun: OPEN
foo: ABSTRACT
staticStr: FINAL PRIVATE
s1: FINAL
i1: FINAL PROTECTED JAVA_STATIC

In some ways, getting it via resolver seems to be returning a more complete information (e.g. OPEN modifier is added).

from ksp.

neetopia avatar neetopia commented on May 7, 2024

some more information.

Seems like it is an issue specific to KSFunctionDeclarationDescriptorImpl while it works fine with KSFunctionDeclarationJavaImpl.

More specifically, if I get a class via resolver.getClassDeclarationByName, it returns KSClassDeclarationDescriptorImpl whereas if i get it via a kotlin subclass (symbol.superTypes.first().resolve()?.declaration), then it returns KSClassDeclarationJavaImpl and it works properly.

So seems like an issue in resolver.
I think the fix is straightforward to extend the check to handle protected but i'm not sure if that'll just hide another bug.
Why does the resolver return two different implementations based on the call site?

They should always be same implementation, I noticed this issue last week but since the fix was rather small and inside the implementation detail therefore I didn't make it an issue, was planning to address it myself, sorry for the confusion.

from ksp.

neetopia avatar neetopia commented on May 7, 2024

I tried extending the javaModifiers test and the value returned from java are a bit different:

C: PUBLIC ABSTRACT
staticStr: PRIVATE
s1: FINAL JAVA_TRANSIENT
i1: PROTECTED JAVA_STATIC JAVA_VOLATILE
intFun: JAVA_SYNCHRONIZED JAVA_DEFAULT
foo: ABSTRACT JAVA_STRICT
abstractVoidMethod: PROTECTED

If I visit the declaration by directly getting it via:

resolver.getClassDeclarationByName(
      resolver.getKSNameFromString("C")
)

it prints:

C: ABSTRACT PUBLIC
abstractVoidMethod: OPEN PROTECTED
hashCode: OPEN PUBLIC OVERRIDE
equals: OPEN PUBLIC OPERATOR OVERRIDE
toString: OPEN PUBLIC OVERRIDE
intFun: OPEN
foo: ABSTRACT
staticStr: FINAL PRIVATE
s1: FINAL
i1: FINAL PROTECTED JAVA_STATIC

In some ways, getting it via resolver seems to be returning a more complete information (e.g. OPEN modifier is added).

It's true that descriptors contains most detailed information as they are fully resolved, but they are not representing the original code structure, like the implicit OPEN for Java symbols, and hence it will be nice if users won't rely on this buggy behavior of getClassDeclarationByName always returns descriptor based implementation.

from ksp.

yigit avatar yigit commented on May 7, 2024

i think both are probably fine from developer's perspective as long as it is consistent. but when they are inconsistent, it will be really hard to workaround as most of the code in the symbol processor does not necessarily know how the KSClassDeclaration was acquired.

from ksp.

neetopia avatar neetopia commented on May 7, 2024

i think both are probably fine from developer's perspective as long as it is consistent. but when they are inconsistent, it will be really hard to workaround as most of the code in the symbol processor does not necessarily know how the KSClassDeclaration was acquired.

If consistent mean .isOpen() will return always return true for an open class regardless of JavaImpl or DescriptorImpl, they are consistent by our design. We are making modifiers only include explicit modifier just to make sure there is a way to still inspect code. Developers should look at utility functions like isOpen rather than relying on modifiers which can differ by platform.

from ksp.

yigit avatar yigit commented on May 7, 2024

I agree with that.
actually i was leaning for the same thing as i'm prototyping the abstraction for room.
I found some places where we unnecessarily access elements APIs. Trying to guard them beyond an abstraction to avoid modelling too much of the elements API.

from ksp.

neetopia avatar neetopia commented on May 7, 2024

android/kotlin#51 includes a fix to this reproduce project.

from ksp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.