Fix exception in light classes when type alias in MultifileClass

#KT-27355 Fixed
This commit is contained in:
Denis Zharkov
2018-10-10 15:19:24 +03:00
parent dc750cdbb3
commit 75dc8ce1c3
2 changed files with 12 additions and 1 deletions
@@ -246,7 +246,7 @@ class MultifileClassCodegenImpl(
val facadeContext = state.rootContext.intoMultifileClass(packageFragment, facadeClassType, partType)
val memberCodegen = createCodegenForDelegatesInMultifileFacade(facadeContext)
for (declaration in CodegenUtil.getDeclarationsToGenerate(file, state.bindingContext)) {
if (declaration is KtNamedFunction || declaration is KtProperty || declaration is KtTypeAlias) {
if (shouldGenerateInFacade(declaration)) {
val descriptor = state.bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)
if (descriptor !is MemberDescriptor) {
throw AssertionError("Expected callable member, was " + descriptor + " for " + declaration.text)
@@ -256,6 +256,15 @@ class MultifileClassCodegenImpl(
}
}
private fun shouldGenerateInFacade(declaration: KtDeclaration): Boolean {
if (declaration is KtNamedFunction || declaration is KtProperty) return true
// In light classes, we intentionally do not analyze type aliases, since they're metadata-only
if (declaration is KtTypeAlias && state.classBuilderMode.generateMetadata) return true
return false
}
private fun shouldGenerateInFacade(descriptor: MemberDescriptor): Boolean {
if (Visibilities.isPrivate(descriptor.visibility)) return false
if (AsmUtil.getVisibilityAccessFlag(descriptor) == Opcodes.ACC_PRIVATE) return false
@@ -6,3 +6,5 @@
package test
val foo = 42
typealias A = String