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

Deprecate API that uses javax.lang.model.type and java.lang.reflect #845

Closed
Egorand opened this issue Dec 18, 2019 · 4 comments
Closed

Deprecate API that uses javax.lang.model.type and java.lang.reflect #845

Egorand opened this issue Dec 18, 2019 · 4 comments

Comments

@Egorand
Copy link
Collaborator

Egorand commented Dec 18, 2019

We track a number of issues that stem from the fact that introspecting Kotlin code through mirrors or reflection is unreliable (#86, #236, #828). Now that there's proper support for processing @Metadata, existing API that has been ported from JavaPoet needs to be deprecated and eventually removed in 2.0. We might need to look into providing more documentation or migration recipes.

@Egorand
Copy link
Collaborator Author

Egorand commented Dec 18, 2019

I think Zac put it perfectly here:

In short: cases like TypeMirror.asTypeName() or Type.asTypeName() will never work as intended for Kotlin compiler intrinsic types. APIs like this simply cannot look at individual types in isolation and have enough context to understand them. You must have access to the appropriate metadata that describes them in context. There are no silver bullets here, this is how Kotlin works.

@Egorand Egorand added this to the 1.5 milestone Dec 25, 2019
@ZacSweers
Copy link
Collaborator

What would the scope of this be? I think it makes sense for cases like overriding but for plain old String::class.asTypeName() is fine. The problem is narrowing it down for intrinsic types, where we may want to check at runtime and ask them to explicitly declare which type to use?

@Egorand
Copy link
Collaborator Author

Egorand commented Dec 26, 2019

I don't think fixing these APIs is the right solution since the safest APIs still are Metadata-based. Of course in an out-of-context snippet of code it's easier to do asTypeName() than to navigate up to find Metadata, but this is unsafe and will yield incorrect results.

@Egorand Egorand modified the milestones: 1.5, 1.6.0 Jan 9, 2020
@Egorand
Copy link
Collaborator Author

Egorand commented Jun 2, 2020

Fixed by #919

@Egorand Egorand closed this as completed Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants