From c68ac4f6b676ebd8d8a589490c11c0fe38741418 Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Thu, 8 Apr 2021 16:46:17 +0200 Subject: [PATCH] [interop][c][reverse] avoid generating empty structures for leaf packages without exportable declations - fixes KT-42796 --- .../org/jetbrains/kotlin/backend/konan/CAdapterGenerator.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterGenerator.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterGenerator.kt index 1a2a18dc4cc..8b1d7c70daa 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterGenerator.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterGenerator.kt @@ -763,7 +763,11 @@ internal class CAdapterGenerator(val context: Context) : DeclarationDescriptorVi } } + private fun ExportedElementScope.hasNonEmptySubScopes(): Boolean = elements.isNotEmpty() || scopes.any { it.hasNonEmptySubScopes() } + private fun makeScopeDefinitions(scope: ExportedElementScope, kind: DefinitionKind, indent: Int) { + if (!scope.hasNonEmptySubScopes()) + return if (kind == DefinitionKind.C_HEADER_STRUCT) output("struct {", indent) if (kind == DefinitionKind.C_SOURCE_STRUCT) output(".${scope.name} = {", indent) scope.elements.forEach { makeElementDefinition(it, kind, indent + 1) }