Skip to content

Commit

Permalink
Fix API break in `Sealed interface used in Composable MUST be Immutab…
Browse files Browse the repository at this point in the history
…le or Stable`
  • Loading branch information
bmarty committed Nov 26, 2024
1 parent e261f6f commit a84ca7e
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,22 @@ class KonsistArchitectureTest {
.assertTrue(additionalMessage = "Consider adding the @Immutable or @Stable annotation to the sealed interface") {
val result = it.parameters.all { param ->
val type = param.type.text
return@all if (type.startsWith("@") || type.startsWith("(") || type.startsWith("suspend")) {
return@all if (type.startsWith("@") || type.contains("->") || type.startsWith("suspend")) {
true
} else {
var typePackage = param.type.declaration.packagee?.name
if (typePackage == type) {
// Workaround, now that packagee.fullyQualifiedName is not available anymore
// It seems that when the type in in the same package as the function,
// the package is equal to the type (which is wrong).
// So in this case, use the package of the function
typePackage = it.packagee?.name
val typePackage = param.type.sourceDeclaration?.let { declaration ->
declaration.asTypeParameterDeclaration()?.packagee
?: declaration.asExternalDeclaration()?.packagee
?: declaration.asClassOrInterfaceDeclaration()?.packagee
?: declaration.asKotlinTypeDeclaration()?.packagee
?: declaration.asObjectDeclaration()?.packagee
}?.name
if (typePackage == null) {
false
} else {
val fullyQualifiedName = "$typePackage.$type"
fullyQualifiedName !in forbiddenInterfacesForComposableParameter
}
val fullyQualifiedName = "$typePackage.$type"
fullyQualifiedName !in forbiddenInterfacesForComposableParameter
}
}
if (!result && !failingTestFound && it.name == "FailingComposableWithNonImmutableSealedInterface") {
Expand Down

0 comments on commit a84ca7e

Please sign in to comment.