From a84ca7ee8e29157a63fd17afd143bfebe2d64d46 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 26 Nov 2024 11:39:33 +0100 Subject: [PATCH] Fix API break in `Sealed interface used in Composable MUST be Immutable or Stable` --- .../tests/konsist/KonsistArchitectureTest.kt | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistArchitectureTest.kt b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistArchitectureTest.kt index 365449a91d..d334d88b55 100644 --- a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistArchitectureTest.kt +++ b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistArchitectureTest.kt @@ -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") {