|
6 | 6 | title="Annotation type-safety" id="annotation-type-safety"> |
7 | 7 |
|
8 | 8 | <p> |
9 | | - Library introduces a concept of annotation type-safety. Consider the following example: |
| 9 | + The library introduces a concept of annotation type-safety. Consider the following example: |
10 | 10 | </p> |
11 | 11 | <code-block lang="Kotlin"> |
12 | 12 | @Rpc |
|
17 | 17 | fun <T : RemoteService> withService() {} |
18 | 18 | </code-block> |
19 | 19 | <p> |
20 | | - Compiler can not guarantee, that the passed type is the one for which the code generation was run: |
| 20 | + The compiler can't guarantee that the passed type parameter is the one for which the code generation was run: |
21 | 21 | </p> |
22 | 22 | <code-block lang="Kotlin"> |
23 | 23 | withService<MyService>() // ok |
24 | 24 | withService<MyServiceImpl>() // compile time ok, runtime throws |
25 | 25 | </code-block> |
26 | 26 | <p> |
27 | | - Our compiler plugin, however, can make this code behave as expected. |
| 27 | + The compiler plugin enforces annotation type-safety by requiring type parameters to have specific annotations, |
| 28 | + like <code>@Rpc</code>. |
28 | 29 | </p> |
29 | 30 | <code-block lang="Kotlin"> |
30 | 31 | @Rpc |
|
41 | 42 | </code-block> |
42 | 43 |
|
43 | 44 | <note> |
44 | | - Annotation type safety only ensures that the resolved type parameters are annotated with the required annotation. |
| 45 | + Annotation type safety only ensures that the resolved type parameters are annotated with the required |
| 46 | + annotation. |
45 | 47 | The actual type of the passed argument may differ: |
46 | 48 | <code-block lang="Kotlin"> |
47 | 49 | fun <@Rpc T : Any> registerService(body: () -> T) {} |
48 | 50 |
|
49 | | - // ok, T is resolved to MyService, |
50 | | - // but 'body' parameter returns MyServiceImpl |
| 51 | + // T is resolved to MyService, |
| 52 | + // but 'body' returns MyServiceImpl |
51 | 53 | registerService<MyService> { ctx -> MyServiceImpl(ctx) } |
52 | 54 |
|
53 | | - // error, T is resolved to MyServiceImpl |
| 55 | + // Error: T is resolved to MyServiceImpl |
54 | 56 | registerService { ctx -> MyServiceImpl(ctx) } |
55 | 57 | </code-block> |
56 | 58 | </note> |
57 | 59 |
|
58 | 60 | <warning> |
59 | | - The feature is highly experimental. |
60 | | - The concept will stay, however due to the complexity of the implementation, |
61 | | - our compiler plugin may behave unexpectedly when performing type-safety checks. |
62 | | - Please, <a href="https://github.com/Kotlin/kotlinx-rpc/issues/new?template=bug_report.md">report</a> any encountered bugs. |
| 61 | + This feature is highly experimental and may lead to unexpected behaviour. If you encounter any issues, |
| 62 | + please <a href="https://github.com/Kotlin/kotlinx-rpc/issues/new?template=bug_report.md">report</a> them. |
63 | 63 |
|
64 | | - To ensure critical bugs don't paralyze your app, there is a kill-switch present for the feature: |
| 64 | + To prevent critical bugs from affecting your app, you can disable this feature using the following |
| 65 | + configuration: |
65 | 66 | <code-block lang="Kotlin"> |
66 | 67 | // build.gradle.kts |
67 | 68 | rpc { |
|
0 commit comments