kotlinpoet icon indicating copy to clipboard operation
kotlinpoet copied to clipboard

Incorrect generation for boxed primitives when used as generics

Open ansman opened this issue 8 years ago • 6 comments

If you read the type SomeClass<Integer> and write it you get SomeClass<Integer> rather than SomeClass<Int>. The generated code compiles but complains that Integer should not be used.

ansman avatar Jun 26 '17 12:06 ansman

Just to be clear, you want Java types automatically converted to Kotlin types when you parse them from an element or mirror?

On Mon, Jun 26, 2017, 7:28 AM Nicklas Ansman Giertz < [email protected]> wrote:

If you read the type SomeClass<Integer> and write it you get SomeClass<Integer> rather than SomeClass<Int>. The generated code compiles but complains that Integer should not be used.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/square/kotlinpoet/issues/139, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEduNVAssONWm5zRb0FW3IkAUk6tZks5sH6QJgaJpZM4OFPf6 .

JakeWharton avatar Jun 26 '17 17:06 JakeWharton

Yes, exactly. I think that should be fine for all cases, right?

ansman avatar Jun 26 '17 18:06 ansman

Seems fine. Want to send a PR?

On Mon, Jun 26, 2017, 1:02 PM Nicklas Ansman Giertz < [email protected]> wrote:

Yes, exactly. I think that should be fine for all cases, right?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/square/kotlinpoet/issues/139#issuecomment-311135766, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEVai1vld81XO_qA7Ex4-r5fbiISCks5sH_I9gaJpZM4OFPf6 .

JakeWharton avatar Jun 26 '17 18:06 JakeWharton

What I see is that kotlin.String, when read from TypeMirror, is seen as java.lang.String. Is there a clever trick to fix this, or do we have to manually map it back into kotlin.String to create ClassName?

Egorand avatar Jun 26 '17 21:06 Egorand

There's no such thing as kotlin.String when running on the JVM, so yes, that's expected.

On Mon, Jun 26, 2017, 4:24 PM Egor Andreevici [email protected] wrote:

What I see is that kotlin.String, when read from TypeMirror, is seen as java.lang.String. Is there a clever trick to fix this, or do we have to manually map it back into kotlin.String to create ClassName?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/square/kotlinpoet/issues/139#issuecomment-311186445, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEcyQiy81kaAg5dsTeGqtdbbW3IUiks5sICGogaJpZM4OFPf6 .

JakeWharton avatar Jun 26 '17 22:06 JakeWharton

Yeah, I'll add a PR

ansman avatar Jun 29 '17 07:06 ansman