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

Added basic CheckedTypeAnnotation impl with compiler plugin check #240

Merged
merged 6 commits into from
Dec 2, 2024

Conversation

Mr3zee
Copy link
Collaborator

@Mr3zee Mr3zee commented Nov 28, 2024

Subsystem
Compiler Plugin, Core

Problem Description
Simple type-safety is not applicable for code generated entities.
If you have code like this:

@Rpc
interface MyService : RemoteService

class MyServiceImpl : MyService

fun <T : RemoteService> withService() {}

You can not guarantee in compile time, that the passed type is the one for which the code generation was run:

withService<MyService>() // ok
withService<MyServiceImpl>() // compile time ok, runtime throws

Solution
Introduce annotation based type-safety:

@Rpc
interface MyService

class MyServiceImpl : MyService

// type is marked with the same annotation it expects from the argument
fun <@Rpc T : Any> withService() {}

Results in

withService<MyService>() // ok
withService<MyServiceImpl>() // compile time error

@Mr3zee Mr3zee added feature New feature or request breaking Contains breaking changes labels Nov 28, 2024
@Mr3zee Mr3zee self-assigned this Nov 28, 2024
@Mr3zee Mr3zee force-pushed the annotation-type-safety branch from a66d486 to f39539c Compare November 28, 2024 15:31
@Mr3zee Mr3zee force-pushed the annotation-type-safety branch from f39539c to db08c2e Compare November 29, 2024 10:13
@Mr3zee Mr3zee requested a review from e5l November 29, 2024 10:15
@Mr3zee Mr3zee marked this pull request as ready for review November 29, 2024 10:15
@Mr3zee Mr3zee changed the title Added basic CheckedTypeAnnotation impl with compiler the plugin check Added basic CheckedTypeAnnotation impl with compiler plugin check Dec 2, 2024
@Mr3zee Mr3zee merged commit 3bab585 into main Dec 2, 2024
6 checks passed
@Mr3zee Mr3zee deleted the annotation-type-safety branch December 2, 2024 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Contains breaking changes feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants