Skip to content

Support override return type generic #102

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

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

ForteScarlet
Copy link
Owner

@ForteScarlet ForteScarlet commented Jul 8, 2025

  /**
    * Indicates whether there is a generic type used to override the function return type
    * on the current mark annotation.
    *
    * If `true`, when determining the return type of the generated function,
    * the content of this generic type will be directly regarded as the return type of the origin function,
    * rather than the actual type of the origin function.
    *
    * For example, Normally, the return type of the generated function
    * depends on the return type of the origin function:
    *
    * ```Kotlin
    * @JvmBlocking
    * suspend fun run(): Result<String>
    *
    * // Generated
    *
    * @Api4J
    * fun runBlocking(): Result<String>
    * ```
    *
    * However, if the annotation has a generic type and `hasReturnTypeOverrideGeneric` is true:
    *
    * ```Kotlin
    * @JvmBlockingWithType<String?>
    * suspend fun run(): Result<String>
    *
    * // Generated
    *
    * @Api4J
    * fun runBlocking(): String?
    * ```
    *
    * As can be seen, the generated function ignores the actual return type of the origin function
    * and instead treats the generic type specified in the annotation as the return type
    * of the origin function.
    *
    * Note: If you want to determine the return type through type overloading,
    * you must ensure that the transformer function you use correctly matches the input and output parameter types.
    * Otherwise, it may result in compilation errors or runtime exceptions.
    *
    * @since 0.14.0
    */
   @ExperimentalReturnTypeOverrideGenericApi
   val hasReturnTypeOverrideGeneric: Property<Boolean>

See also: #99

…rt for generic-based return type overrides, and update related configurations and annotations.
@ForteScarlet ForteScarlet self-assigned this Jul 8, 2025
@ForteScarlet ForteScarlet added the enhancement New feature or request label Jul 8, 2025
@ForteScarlet ForteScarlet changed the title try-support-annotation-generics Support override return type generic Jul 8, 2025
@ForteScarlet ForteScarlet added this to the 0.14.0 milestone Jul 8, 2025
…urations, and introduce `test-runner` module with generic return type support.
…t usages across the plugin, and improve transformer initialization with type parameter caching.
…etter organization and maintainability within the FIR transformer module.
But then a second problem arose: it seemed that there was a problem with using inline value classes when using generics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant