From f618ea05f75ba3b2875a5abeda9f94812c38e2cb Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 10 Aug 2026 14:28:44 +0600 Subject: [PATCH] fix in generate sealed workaround --- ksp/sealed/generator/src/main/kotlin/Processor.kt | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/ksp/sealed/generator/src/main/kotlin/Processor.kt b/ksp/sealed/generator/src/main/kotlin/Processor.kt index f46ae51775e..95a2d2cf236 100644 --- a/ksp/sealed/generator/src/main/kotlin/Processor.kt +++ b/ksp/sealed/generator/src/main/kotlin/Processor.kt @@ -53,7 +53,7 @@ class Processor( val annotation = ksClassDeclaration.getGenerateSealedWorkaroundAnnotation val subClasses = ksClassDeclaration.resolveSubclasses( searchIn = resolver.getAllFiles(), - allowNonSealed = annotation ?.includeNonSealedSubTypes ?: false + allowNonSealed = withNoSuchElementWorkaround(null) { annotation ?.includeNonSealedSubTypes } ?: false ).distinct() val subClassesNames = subClasses.filter { when (it.classKind) { @@ -165,15 +165,7 @@ class Processor( @OptIn(KspExperimental::class) override fun process(resolver: Resolver): List { (resolver.getSymbolsWithAnnotation(GenerateSealedWorkaround::class.qualifiedName!!)).filterIsInstance().forEach { - val prefix = runCatching { - (it.getGenerateSealedWorkaroundAnnotation) ?.prefix - }.getOrElse { - if (it is NoSuchElementException) { - "" - } else { - throw it - } - } ?.takeIf { + val prefix = withNoSuchElementWorkaround(null) { (it.getGenerateSealedWorkaroundAnnotation) ?.prefix } ?.takeIf { it.isNotEmpty() } ?: it.buildSubFileName.replaceFirst(it.simpleName.asString(), "") it.writeFile(prefix = prefix, suffix = "SealedWorkaround") {