https://kotlinlang.org logo
#arrow
Title
s

sindrenm

07/13/2023, 11:18 AM
With optics-ksp-plugin 1.2.0, generated code using wildcard generics does not compile. Wildcard generics
<*>
gets replaced with
<* kotlin.Any?>
. See example in thread.
Copy code
@optics
data class GenericType<A>(
  val field1: A
) { companion object }

@optics
data class IsoData(val genericType: GenericType<*>) {
  companion object
}
generates:
Copy code
public inline val IsoData.Companion.iso: Iso<IsoData, GenericType<* kotlin.Any?>> inline get() = Iso(
  get = { isoData: IsoData -> isoData.genericType },
  reverseGet = { IsoData(it) }
)

public inline val IsoData.Companion.genericType: Lens<IsoData, GenericType<* kotlin.Any?>> inline get() = Lens(
  get = { isoData: IsoData -> isoData.`genericType` },
  set = { isoData: IsoData, value: GenericType<* kotlin.Any?> -> isoData.copy(`genericType` = value) }
)

public inline val <S> Iso<S, IsoData>.genericType: Lens<S, GenericType<* kotlin.Any?>> inline get() = this + IsoData.genericType
public inline val <S> Lens<S, IsoData>.genericType: Lens<S, GenericType<* kotlin.Any?>> inline get() = this + IsoData.genericType
public inline val <S> Optional<S, IsoData>.genericType: Optional<S, GenericType<* kotlin.Any?>> inline get() = this + IsoData.genericType
public inline val <S> Prism<S, IsoData>.genericType: Optional<S, GenericType<* kotlin.Any?>> inline get() = this + IsoData.genericType
public inline val <S> Getter<S, IsoData>.genericType: Getter<S, GenericType<* kotlin.Any?>> inline get() = this + IsoData.genericType
public inline val <S> Setter<S, IsoData>.genericType: Setter<S, GenericType<* kotlin.Any?>> inline get() = this + IsoData.genericType
public inline val <S> Traversal<S, IsoData>.genericType: Traversal<S, GenericType<* kotlin.Any?>> inline get() = this + IsoData.genericType
public inline val <S> Fold<S, IsoData>.genericType: Fold<S, GenericType<* kotlin.Any?>> inline get() = this + IsoData.genericType
public inline val <S> Every<S, IsoData>.genericType: Every<S, GenericType<* kotlin.Any?>> inline get() = this + IsoData.genericType
GenericType<* kotlin.Any?>
is the culprit and should just be
GenericType<*>
.
Upon further inspection, it seems 1.1.5 generated
GenericType<kotlin.Any?>
, actually, which of course also compiles.
a

Alejandro Serrano Mena

07/13/2023, 1:42 PM
I guess this may be related to the new support for variance in 1.2.0
s

sindrenm

07/13/2023, 2:07 PM
Damn, that was quick! Thanks! 🎉