diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt index 6725c87842c..5a699b4f383 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt @@ -10,6 +10,7 @@ import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.KSTypeArgument import com.google.devtools.ksp.symbol.KSTypeParameter import com.google.devtools.ksp.symbol.Variance.INVARIANT +import com.google.devtools.ksp.symbol.Variance.STAR import java.util.Locale internal fun adt(c: KSClassDeclaration, logger: KSPLogger): ADT = @@ -180,7 +181,11 @@ internal fun KSType.qualifiedString(prefix: String = ""): String = when (declara internal fun KSTypeArgument.qualifiedString(): String = when (val ty = type?.resolve()) { null -> toString() - else -> ty.qualifiedString(prefix = "${variance.label} ".takeIf { variance != INVARIANT }.orEmpty()) + else -> when (variance) { + STAR -> "*" + INVARIANT -> ty.qualifiedString() + else -> ty.qualifiedString(prefix = "${variance.label} ") + } } internal fun KSClassDeclaration.getConstructorParamNames(): List = diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/LensTests.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/LensTests.kt index 3bc1e13ee91..4eb45199c16 100755 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/LensTests.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/LensTests.kt @@ -113,4 +113,21 @@ class LensTests { |val r = i != null && j != null """.evals("r" to true) } + + @Test + fun `Lenses for STAR arguments`() { + """ + |$`package` + |$imports + |@optics + |data class GenericType( + | val field1: A + |) { companion object } + | + |@optics + |data class IsoData(val genericType: GenericType<*>) { + | companion object + |} + """.compilationSucceeds() + } }