Skip to content

Conversation

@ForteScarlet
Copy link
Owner

Before

build:

useJvmDefault()
// or 

addJvmTransformer(
  Transformer(
    ...,
    syntheticFunctionIncludeAnnotations = listOf(
                IncludeAnnotation(jvmApi4JAnnotationClassInfo)
            )
  )
)

Then the source:

class Foo {
    @JvmBlocking(asProperty = true)
    suspend value(): Int = 1
}

the compiled:

class Foo {
    @JvmSynthetic
    suspend value(): Int = 1

    val valueBlocking: Int
        @Api4J // Problem: RequiresOptIn doesn't work on getters.
        get() = runInBlocking { value() }
}

After

build:

useJvmDefault()
// or 

addJvmTransformer(
  Transformer(
    ...,
    syntheticFunctionIncludeAnnotations = listOf(
                IncludeAnnotation(jvmApi4JAnnotationClassInfo).apply {
                    includeProperty = true 
                    // 👆 support for including to the property
                }
            )
  )
)

Then the source:

class Foo {
    @JvmBlocking(asProperty = true)
    suspend value(): Int = 1
}

the compiled:

class Foo {
    @JvmSynthetic
    suspend value(): Int = 1

    @Api4J // Included to this property
    val valueBlocking: Int
        @Api4J
        get() = runInBlocking { value() }
}

@ForteScarlet ForteScarlet added the enhancement New feature or request label Jun 12, 2024
@ForteScarlet ForteScarlet merged commit 97105d9 into dev Jun 12, 2024
@ForteScarlet ForteScarlet deleted the support-include-property-annotation branch June 12, 2024 12:48
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.

2 participants