@@ -161,23 +161,35 @@ private class CirTreeSerializationVisitor(
161
161
nestedClass
162
162
}
163
163
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
+
164
170
val nestedConstructors: Collection <KmConstructor > = node.constructors.mapNotNull { (constructorKey, constructorNode) ->
165
171
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
167
175
statsCollector?.logClassConstructor(constructor , constructorContext, constructorKey)
168
176
constructor
169
177
}
170
178
171
179
val nestedFunctions: Collection <KmFunction > = node.functions.mapNotNull { (functionKey, functionNode) ->
172
180
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
174
184
statsCollector?.logFunction(function, functionContext, functionKey)
175
185
function
176
186
}
177
187
178
188
val nestedProperties: Collection <KmProperty > = node.properties.mapNotNull { (propertyKey, propertyNode) ->
179
189
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
181
193
statsCollector?.logProperty(propertyContext, propertyKey, propertyNode)
182
194
property
183
195
}
0 commit comments