Skip to content

Commit

Permalink
Fix problem with optics and <*> generics
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Jul 13, 2023
1 parent dd6a062 commit d36cf26
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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<String> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<A>(
| val field1: A
|) { companion object }
|
|@optics
|data class IsoData(val genericType: GenericType<*>) {
| companion object
|}
""".compilationSucceeds()
}
}

0 comments on commit d36cf26

Please sign in to comment.