Fix generation of companion object inside inline classes

This commit is contained in:
Mikhail Zarechenskiy
2018-02-06 14:33:14 +03:00
parent e1d3b21201
commit 70cd1cfcdf
5 changed files with 47 additions and 15 deletions
@@ -54,7 +54,7 @@ public abstract class ClassBodyCodegen extends MemberCodegen<KtPureClassOrObject
@Override
protected void generateBody() {
List<KtObjectDeclaration> companions = new ArrayList<>();
if (kind != OwnerKind.DEFAULT_IMPLS) {
if (kind != OwnerKind.DEFAULT_IMPLS && kind != OwnerKind.ERASED_INLINE_CLASS) {
//generate nested classes first and only then generate class body. It necessary to access to nested CodegenContexts
for (KtDeclaration declaration : myClass.getDeclarations()) {
if (shouldProcessFirst(declaration)) {
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.codegen;
@@ -39,7 +28,7 @@ public class FieldInfo {
ClassDescriptor ownerDescriptor = DescriptorUtils.getParentOfType(classDescriptor, ClassDescriptor.class);
assert ownerDescriptor != null : "Owner not found for class: " + classDescriptor;
Type ownerType = typeMapper.mapType(ownerDescriptor);
Type ownerType = typeMapper.mapClass(ownerDescriptor);
return new FieldInfo(ownerType, typeMapper.mapType(classDescriptor), classDescriptor.getName().asString(), true);
}
@@ -0,0 +1,11 @@
// !LANGUAGE: +InlineClasses
inline class Foo(val x: Int) {
companion object {
fun funInCompanion() {}
private const val constValInCompanion = 1
}
fun inInlineClass() {}
}
@@ -0,0 +1,26 @@
@kotlin.Metadata
public final class Foo$Companion {
inner class Foo$Companion
private method <init>(): void
public synthetic method <init>(p0: kotlin.jvm.internal.DefaultConstructorMarker): void
public final method funInCompanion(): void
}
@kotlin.Metadata
public final static class Foo$Erased {
public final static @org.jetbrains.annotations.NotNull method box(p0: int): Foo
public final static method inInlineClass(p0: int): void
}
@kotlin.Metadata
public final class Foo {
public final static field Companion: Foo$Companion
private final static field constValInCompanion: int
private final field x: int
inner class Foo$Companion
static method <clinit>(): void
public method <init>(p0: int): void
public final method getX(): int
public final method inInlineClass(): void
public final method unbox(): int
}
@@ -267,6 +267,12 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("companionObjectInsideInlineClass.kt")
public void testCompanionObjectInsideInlineClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/inlineClasses/companionObjectInsideInlineClass.kt");
doTest(fileName);
}
@TestMetadata("noBridgesForErasedInlineClass.kt")
public void testNoBridgesForErasedInlineClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/inlineClasses/noBridgesForErasedInlineClass.kt");