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

FunSpec.overriding does not handle internal methods correctly #828

Closed
Leland-Takamine opened this issue Nov 5, 2019 · 5 comments
Closed

Comments

@Leland-Takamine
Copy link

Leland-Takamine commented Nov 5, 2019

Repro Steps

git clone git@github.com:Leland-Takamine/kotlinpoet-repro.git
cd kotlinpoet-repro
./gradlew :build
# Build fails

Explanation

Method to be overridden
class Foo {
    internal abstract fun myMethod()
}
Overriding method generated via FunSpec.overriding(...)
class FooImpl : Foo() {
  override fun myMethod$repro(): Unit = throw UnsupportedOperationException()
}

Notice that the generated method includes the $repro suffix. This is due to the fact that Kotlin mangles the names of internal methods.

Possible Solution

KotlinPoet should inspect the Kotlin metadata to use the original method name for overriding.

@Leland-Takamine
Copy link
Author

@tyvsmith @kurtisnelson

@ZacSweers
Copy link
Collaborator

Heavily discussed in #236

@Egorand
Copy link
Collaborator

Egorand commented Nov 7, 2019

@Leland-Takamine KotlinPoet does work with Kotlin metadata but through different API, please refer to https://github.com/square/kotlinpoet/blob/master/kotlinpoet-metadata-specs/README.md and https://github.com/square/kotlinpoet/blob/master/kotlinpoet-metadata/README.md.

We should probably deprecate existing introspection API since they don't work well with Kotlin.

@ZacSweers
Copy link
Collaborator

+1 on deprecating the existing. It's a straight port from javapoet but is wrong often enough to be untrustworthy

@ZacSweers
Copy link
Collaborator

Folding this into #236 since it's basically a duplicate of the discussion there.

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

No branches or pull requests

3 participants