diff --git a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt index ab0ac552182..e1eeadd3333 100644 --- a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt +++ b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt @@ -98,16 +98,27 @@ private class NativeIndexImpl : NativeIndex() { * Computes [StructDef.hasNaturalLayout] property. */ fun structHasNaturalLayout(structDefCursor: CXCursor): Boolean { - val hasAttributes = malloc(Int32Box) - hasAttributes.value = 0 - clang_visitChildren(structDefCursor, { cursor, parent, clientData -> - if (clang_isAttribute(cursor.kind.value) != 0) { - clientData.asRef(Int32Box)!!.value = 1 - } - CXChildVisitResult.CXChildVisit_Continue - }, hasAttributes.ptr) + val defKind = structDefCursor.kind.value - return hasAttributes.value == 0 + when (defKind) { + + CXCursorKind.CXCursor_UnionDecl -> return false + + CXCursorKind.CXCursor_StructDecl -> { + val hasAttributes = malloc(Int32Box) + hasAttributes.value = 0 + clang_visitChildren(structDefCursor, { cursor, parent, clientData -> + if (clang_isAttribute(cursor.kind.value) != 0) { + clientData.asRef(Int32Box)!!.value = 1 + } + CXChildVisitResult.CXChildVisit_Continue + }, hasAttributes.ptr) + + return hasAttributes.value == 0 + } + + else -> throw IllegalArgumentException(defKind.toString()) + } } fun convertType(type: CXType): Type {