Fix for KT-14012: Back-end (JVM) Internal error every first compilation after the source code change

#KT-14012 Fixed
This commit is contained in:
Michael Bogdanov
2016-10-17 12:16:13 +03:00
parent 783e5e9083
commit d48ef2efc7
14 changed files with 153 additions and 6 deletions

View File

@@ -83,6 +83,7 @@ import java.util.List;
import static org.jetbrains.kotlin.codegen.AsmUtil.isStaticMethod;
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.*;
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.*;
import static org.jetbrains.kotlin.fileClasses.JvmFileClassUtil.getPartFqNameForDeserializedCallable;
import static org.jetbrains.kotlin.resolve.BindingContextUtils.getDelegationConstructorCall;
import static org.jetbrains.kotlin.resolve.BindingContextUtils.isVarCapturedInClosure;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
@@ -866,12 +867,8 @@ public class KotlinTypeMapper {
if (DescriptorUtils.isTopLevelDeclaration(descriptor)) {
if (Visibilities.isPrivate(descriptor.getVisibility()) && !(descriptor instanceof ConstructorDescriptor) && !"<clinit>".equals(name)) {
KtFile containingFile = DescriptorToSourceUtils.getContainingFile(descriptor);
assert containingFile != null : "Private descriptor accessed outside of corresponding file scope: " + descriptor;
JvmFileClassInfo fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(containingFile);
if (fileClassInfo.getWithJvmMultifileClass()) {
return name + "$" + fileClassInfo.getFileClassFqName().shortName().asString();
}
String partName = getPartSimpleNameForMangling(descriptor);
if (partName != null) return name + "$" + partName;
}
return name;
}
@@ -883,6 +880,28 @@ public class KotlinTypeMapper {
return name;
}
@Nullable
private String getPartSimpleNameForMangling(@NotNull CallableMemberDescriptor descriptor) {
KtFile containingFile = DescriptorToSourceUtils.getContainingFile(descriptor);
if (containingFile != null) {
JvmFileClassInfo fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(containingFile);
if (fileClassInfo.getWithJvmMultifileClass()) {
return fileClassInfo.getFileClassFqName().shortName().asString();
}
return null;
}
descriptor = getDirectMember(descriptor);
assert descriptor instanceof DeserializedCallableMemberDescriptor :
"Descriptor without sources should be instance of DeserializedCallableMemberDescriptor, but: " +
descriptor;
ContainingClassesInfo containingClassesInfo =
getContainingClassesForDeserializedCallable((DeserializedCallableMemberDescriptor) descriptor);
String facadeShortName = containingClassesInfo.getFacadeClassId().getShortClassName().asString();
String implShortName = containingClassesInfo.getImplClassId().getShortClassName().asString();
return !facadeShortName.equals(implShortName) ? implShortName : null;
}
@NotNull
public Method mapAsmMethod(@NotNull FunctionDescriptor descriptor) {
return mapSignature(descriptor, true).getAsmMethod();

View File

@@ -0,0 +1,18 @@
// FILE: A.kt
package test
var property = "fail"
private set
fun test() {
property = "OK"
}
// FILE: B.kt
import test.*
fun box(): String {
test()
return property
}

View File

@@ -0,0 +1,20 @@
// FILE: A.kt
@file:JvmName("TTest")
@file:JvmMultifileClass
package test
var property = "fail"
private set
fun test() {
property = "OK"
}
// FILE: B.kt
import test.*
fun box(): String {
test()
return property
}

View File

@@ -149,6 +149,18 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
doTest(fileName);
}
@TestMetadata("kt14012.kt")
public void testKt14012() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/kt14012.kt");
doTest(fileName);
}
@TestMetadata("kt14012_multi.kt")
public void testKt14012_multi() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/kt14012_multi.kt");
doTest(fileName);
}
@TestMetadata("multifileClassInlineFunctionAccessingProperty.kt")
public void testMultifileClassInlineFunctionAccessingProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/compileKotlinAgainstKotlin/multifileClassInlineFunctionAccessingProperty.kt");

View File

@@ -821,6 +821,18 @@ public class ExperimentalIncrementalJpsTestGenerated extends AbstractExperimenta
doTest(fileName);
}
@TestMetadata("publicPropertyWithPrivateSetter")
public void testPublicPropertyWithPrivateSetter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/publicPropertyWithPrivateSetter/");
doTest(fileName);
}
@TestMetadata("publicPropertyWithPrivateSetterMultiFileFacade")
public void testPublicPropertyWithPrivateSetterMultiFileFacade() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/publicPropertyWithPrivateSetterMultiFileFacade/");
doTest(fileName);
}
@TestMetadata("removeAndRestoreCompanion")
public void testRemoveAndRestoreCompanion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/removeAndRestoreCompanion/");

View File

@@ -821,6 +821,18 @@ public class IncrementalJpsTestGenerated extends AbstractIncrementalJpsTest {
doTest(fileName);
}
@TestMetadata("publicPropertyWithPrivateSetter")
public void testPublicPropertyWithPrivateSetter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/publicPropertyWithPrivateSetter/");
doTest(fileName);
}
@TestMetadata("publicPropertyWithPrivateSetterMultiFileFacade")
public void testPublicPropertyWithPrivateSetterMultiFileFacade() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/publicPropertyWithPrivateSetterMultiFileFacade/");
doTest(fileName);
}
@TestMetadata("removeAndRestoreCompanion")
public void testRemoveAndRestoreCompanion() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/removeAndRestoreCompanion/");

View File

@@ -0,0 +1,11 @@
================ Step #1 =================
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/test2/Prop2Kt.class
End of files
Compiling files:
src/prop2.kt
End of files
Exit code: OK
------------------------------------------

View File

@@ -0,0 +1,4 @@
package test
var property = 1
private set

View File

@@ -0,0 +1,6 @@
package test2
import test.*
fun dummy() {
if (true) 1 else property
}

View File

@@ -0,0 +1,5 @@
package test
fun dummy() {
if (true) 2 else property
}

View File

@@ -0,0 +1,11 @@
================ Step #1 =================
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/test2/Prop2Kt.class
End of files
Compiling files:
src/prop2.kt
End of files
Exit code: OK
------------------------------------------

View File

@@ -0,0 +1,6 @@
@file:JvmName("TTest")
@file:JvmMultifileClass
package test
var property = 1
private set

View File

@@ -0,0 +1,6 @@
package test2
import test.*
fun dummy() {
if (true) 1 else property
}

View File

@@ -0,0 +1,5 @@
package test
fun dummy() {
if (true) 2 else property
}