@@ -161,23 +161,35 @@ private class CirTreeSerializationVisitor(
161161 nestedClass
162162 }
163163
164+ // `protected` members are prohibited inside final expect classes, as they can't be accessed.
165+ fun <T > T.takeIfNeeded (visibility : Visibility ): T ? = when {
166+ cirClass.modality == org.jetbrains.kotlin.descriptors.Modality .FINAL && visibility == Visibility .PROTECTED -> null
167+ else -> this
168+ }
169+
164170 val nestedConstructors: Collection <KmConstructor > = node.constructors.mapNotNull { (constructorKey, constructorNode) ->
165171 val constructorContext = classContext.callableMemberContext(DEFAULT_CONSTRUCTOR_NAME , classTypeParametersCount)
166- val constructor : KmConstructor = constructorNode.accept(this , constructorContext)?.cast() ? : return @mapNotNull null
172+ val constructor : KmConstructor = (constructorNode.accept(this , constructorContext) as ? KmConstructor )
173+ ?.let { it.takeIfNeeded(it.visibility) }
174+ ? : return @mapNotNull null
167175 statsCollector?.logClassConstructor(constructor , constructorContext, constructorKey)
168176 constructor
169177 }
170178
171179 val nestedFunctions: Collection <KmFunction > = node.functions.mapNotNull { (functionKey, functionNode) ->
172180 val functionContext = classContext.callableMemberContext(functionKey.name, classTypeParametersCount)
173- val function: KmFunction = functionNode.accept(this , functionContext)?.cast() ? : return @mapNotNull null
181+ val function: KmFunction = (functionNode.accept(this , functionContext) as ? KmFunction )
182+ ?.let { it.takeIfNeeded(it.visibility) }
183+ ? : return @mapNotNull null
174184 statsCollector?.logFunction(function, functionContext, functionKey)
175185 function
176186 }
177187
178188 val nestedProperties: Collection <KmProperty > = node.properties.mapNotNull { (propertyKey, propertyNode) ->
179189 val propertyContext = classContext.callableMemberContext(propertyKey.name, classTypeParametersCount)
180- val property: KmProperty = propertyNode.accept(this , propertyContext)?.cast() ? : return @mapNotNull null
190+ val property: KmProperty = (propertyNode.accept(this , propertyContext) as ? KmProperty )
191+ ?.let { it.takeIfNeeded(it.visibility) }
192+ ? : return @mapNotNull null
181193 statsCollector?.logProperty(propertyContext, propertyKey, propertyNode)
182194 property
183195 }
0 commit comments