Have anyone experienced this error? It happened ri...
# arrow
i
Have anyone experienced this error? It happened right after enabling
kapt
in this file.
Copy code
> Task :core:kaptDebugKotlinAndroid
Values of variant API AnnotationProcessorOptions.arguments are queried and may return non final values, this is unsupported
/home/iliyan/work/repo/ivy-wallet/core/build/tmp/kapt3/stubs/debug/ivy/core/domain/AccountCacheKt.java:6: error: cannot access Raise
    private static final java.lang.Object invalidateAffectedCaches(ivy.core.persistence.AccountCachePersistence _context_receiver_0, arrow.core.raise.Raise<? super ivy.core.persistence.data.PersistenceError> _context_receiver_1, java.util.List<? extends ivy.core.persistence.data.ItemChange<? super ivy.core.data.Transaction>> changes, kotlin.coroutines.Continuation<? super kotlin.Unit> $completion) {
                                                                                                                                                     ^
  bad class file: /home/iliyan/.gradle/caches/modules-2/files-2.1/io.arrow-kt/arrow-core-jvm/1.2.0-RC/815591a96f11786ae0ff746a4931fee9c0e46ac4/arrow-core-jvm-1.2.0-RC.jar(/arrow/core/raise/Raise.class)
    undeclared type variable: T
    Please remove or make sure it appears in the correct subdirectory of the classpath.

> Task :core:kaptDebugKotlinAndroid FAILED

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':core:kaptKotlinJvm'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
   > java.lang.reflect.InvocationTargetException (no error message)
Copy code
bad class file: /home/iliyan/.gradle/caches/modules-2/files-2.1/io.arrow-kt/arrow-core-jvm/1.2.0-RC/815591a96f11786ae0ff746a4931fee9c0e46ac4/arrow-core-jvm-1.2.0-RC.jar(/arrow/core/raise/Raise.class)
    undeclared type variable: T
    Please remove or make sure it appears in the correct subdirectory of the classpath.
s
We’ve had a couple people report this actually but I have no idea what causes it.. It seems that moving the
Raise
related extension or context receiver function out of the file using kapt fixed the issue. So it seems like some strange but related to kapt but I have no idea how we can be causing it since
Raise
is just an interface.
i
Got it. It also looked weird to me. Any known workarounds? I don't use
kapt
in the
AccountCache.kt
file. I need kapt because of Dagger + Anvil for Slack's Circuit. If there isn't such, I'll have to drop the Dagger + Anvil DI. Tried: • downgrading kapt • upgraded Kotlin Any ideas for things to try?
s
Hmm, that is strange. I’d like to see that fixed and do an RC2 release with a Kotlin 1.8.21 bump
If you could share a reproducible example that would be awesome, or clone Arrow and do a
publishMaven
on your local machine. To do that you need to define an arbitrary
projects.version
in
gradle.properties
. https://github.com/arrow-kt/arrow/blob/c7f3af57106651b0810918e773ed5e546c980943/gradle.properties#L2 Or it will appear as
arrow-core:unspecified
in your
mavenLocal()
repository
i
Thanks! Kotlin 1.8.21 might fix the issue. I'll try to build a minimum reproducible example and share it in #arrow-contributors. The problem is that I can upgrade our project to 1.8.20 because it depends on Compose Multiplatform. But if we upgrade Arrow's Kotlin version in RC2 it might resolve it.
m
I just encountered this issue in my project, too. Using Kotlin 1.9.22 and Arrow 1.2.3. It all started when adding this function to an existing interface, `AbstractRepository<T : Any, I : Any>`:
Copy code
suspend fun manyById(ids: NonEmptySet<I>): Either<DataRetrievalError, NonEmptySet<T>>
I have tried fiddling around with the signature (including getting rid of the
suspend
modifier) but nothing seems to work. After removing the function, it compiles again. The error:
Copy code
bad class file: [...]/api/build/libs/api-0.3.14.jar(/io/redigital/rebased/api/AbstractRepository.class)
    undeclared type variable: A
    Please remove or make sure it appears in the correct subdirectory of the classpath.
I understand that this is probably not really related to Arrow but an issue with kapt. Any tips on what I could do?
Follow-Up: after intermittently stumbling upon issues with
undeclared type variable
in various scenarios, my colleagues and I found that when passing the type parameter of
NonEmptySet
on to our clients, it would only work when naming it
A
. For example, the following method in one of our interfaces would complain `undeclared type variable: A`:
Copy code
operator fun <AT, AF : AggregateFunction<AT>> invoke(
        dataResource: DataResource,
        queryOptions: DataPointQueryOptions,
        aggregateFunctions: NonEmptySet<AF>,
    ): AggregatedValues<AF, AT>
because the type parameter was named
AF
and it was exposed to the interface. After renaming it from
AF
to
A
, everything worked again. I think it might be a good idea to add this to the documentation? Furthermore, it would be interesting to know what makes
NonEmptySet
so special that it causes this behaviour when we never had issues with other interfaces like
Option
that we expose as part of our interfaces, too. Although that could be because usually there's only one type parameter involved and it's named
T
... 🤔
y
That has to be a compiler bug I think. There's nothing special going on with NonEmptySet to cause such behaviour. If you can, make a reproducer and submit an issue to kotl.in/issue
👍 1
m
I'll see whether I can allocate some time - it has something to do with kapt and re-exporting the interface so the reproducer might need some tweaking to capture the essence of the issue.
430 Views