Arrow Core 2 causes undeclared type variable: A when using NonEmptyList
Hi,
when I try to inject with Hilt a component returning NonEmptyList, such as:
internal fun interface StateBuilder {
fun build(): NonEmptyList<String>
}
I'm getting
bad class file: /Users/danielecampogiani/Developing/android/arrow-2-empty-list-issue/app/build/tmp/kotlin-classes/debug/com/danielecampogiani/StateBuilder.class
undeclared type variable: A
Please remove or make sure it appears in the correct subdirectory of the classpath.
I've created a reproducible issue in this repo: https://github.com/dcampogiani/Arrow-Core-2-NonEmptyList-Issue
Dependencies:
- arrowCore = "2.0.0"
- hilt = "2.54"
- kotlin = "2.1.0"
Everything works fine if I use arrowCore=1.2.4, or replace NonEmptyList with List
NonEmptyList v1.2.4 is a normal class.
Since 2.0.0, it is a @JvmInline value class.
Does Hilt/Dagger support @JvmInline value class?
I believe a similar issue has been reported, and a hot fix either has been released or will be released soon. The issue is that the type parameter of Nel needs to have the same name as the type parameter of List, so the fix does precisely that. I'll try to find the related issue
@kyay10 if you are referring to: https://github.com/arrow-kt/arrow/pull/3549, I've tried with version 2.0.1-apha.1 and now the error is:
/Users/danielecampogiani/Developing/android/arrow-2-empty-list-issue/app/build/generated/ksp/debug/java/com/danielecampogiani/MainViewModel_Factory.java:28: error: cannot access StateBuilder
private final Provider<StateBuilder> builderProvider;
^
bad class file: /Users/danielecampogiani/Developing/android/arrow-2-empty-list-issue/app/build/tmp/kotlin-classes/debug/com/danielecampogiani/StateBuilder.class
undeclared type variable: E
Please remove or make sure it appears in the correct subdirectory of the classpath.
From:
undeclared type variable: A
to:
undeclared type variable: E
Thanks for the reproducer. It turns out that this is a reported bug in the Kotlin compiler. It seems that if you use NonEmptyList<String>, the compiler still "leaves" an undeclared type variable standing for the type parameter of NonEmptyList, and which ultimately causes the problem.
Are there any work arounds for this, or do we have to sit tight until the Kotlin compiler bug is fixed?
Unfortunately the only option until the fix is released is to use List<A> instead and perform validation manually.
Thanks for the response @serras, I'll give that a go 😄
Update: the bug is fixed in the compiler, but will be released in 2.2.20. I'll close this issue once it's released and we check it works.
@dcampogiani @hugomd could any of you test whether 2.2.20-Beta1 fixes this issue for you? I think it does, but I'd like to double check before closing this issue.
@serras can I find the 2.2.20-Beta1 deployed anywhere?
@dcampogiani it's deployed as usual, so you can just change your Kotlin version 2.2.20-Beta1 as with any other
Sorry, my bad, I thought 2.2.20-Beta1 was referring to the arrow version. I'll try as soon as I can.
@dcampogiani @hugomd could any of you test whether 2.2.20-Beta1 fixes this issue for you? I think it does, but I'd like to double check before closing this issue.
@serras I've confirmed 2.2.20-Beta1 fixes this for us! The inner type is appropriately propagated 🎉
Thank you for pushing on this, glad to see it finally fixed 🙏🏻