Fix API break in Sealed interface used in Composable MUST be Immutable or Stable
This commit is contained in:
parent
6e162f0a44
commit
4863195a9a
1 changed files with 13 additions and 10 deletions
|
|
@ -80,19 +80,22 @@ class KonsistArchitectureTest {
|
||||||
.assertTrue(additionalMessage = "Consider adding the @Immutable or @Stable annotation to the sealed interface") {
|
.assertTrue(additionalMessage = "Consider adding the @Immutable or @Stable annotation to the sealed interface") {
|
||||||
val result = it.parameters.all { param ->
|
val result = it.parameters.all { param ->
|
||||||
val type = param.type.text
|
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
|
true
|
||||||
} else {
|
} else {
|
||||||
var typePackage = param.type.declaration.packagee?.name
|
val typePackage = param.type.sourceDeclaration?.let { declaration ->
|
||||||
if (typePackage == type) {
|
declaration.asTypeParameterDeclaration()?.packagee
|
||||||
// Workaround, now that packagee.fullyQualifiedName is not available anymore
|
?: declaration.asExternalDeclaration()?.packagee
|
||||||
// It seems that when the type in in the same package as the function,
|
?: declaration.asClassOrInterfaceDeclaration()?.packagee
|
||||||
// the package is equal to the type (which is wrong).
|
?: declaration.asKotlinTypeDeclaration()?.packagee
|
||||||
// So in this case, use the package of the function
|
?: declaration.asObjectDeclaration()?.packagee
|
||||||
typePackage = it.packagee?.name
|
}?.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") {
|
if (!result && !failingTestFound && it.name == "FailingComposableWithNonImmutableSealedInterface") {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue