mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-03 08:31:29 +00:00
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:
@@ -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();
|
||||
|
||||
18
compiler/testData/compileKotlinAgainstKotlin/kt14012.kt
vendored
Normal file
18
compiler/testData/compileKotlinAgainstKotlin/kt14012.kt
vendored
Normal 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
|
||||
}
|
||||
20
compiler/testData/compileKotlinAgainstKotlin/kt14012_multi.kt
vendored
Normal file
20
compiler/testData/compileKotlinAgainstKotlin/kt14012_multi.kt
vendored
Normal 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
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -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/");
|
||||
|
||||
@@ -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/");
|
||||
|
||||
11
jps-plugin/testData/incremental/pureKotlin/publicPropertyWithPrivateSetter/build.log
vendored
Normal file
11
jps-plugin/testData/incremental/pureKotlin/publicPropertyWithPrivateSetter/build.log
vendored
Normal 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
|
||||
------------------------------------------
|
||||
4
jps-plugin/testData/incremental/pureKotlin/publicPropertyWithPrivateSetter/prop1.kt
vendored
Normal file
4
jps-plugin/testData/incremental/pureKotlin/publicPropertyWithPrivateSetter/prop1.kt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
var property = 1
|
||||
private set
|
||||
6
jps-plugin/testData/incremental/pureKotlin/publicPropertyWithPrivateSetter/prop2.kt
vendored
Normal file
6
jps-plugin/testData/incremental/pureKotlin/publicPropertyWithPrivateSetter/prop2.kt
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
package test2
|
||||
import test.*
|
||||
|
||||
fun dummy() {
|
||||
if (true) 1 else property
|
||||
}
|
||||
5
jps-plugin/testData/incremental/pureKotlin/publicPropertyWithPrivateSetter/prop2.kt.new
vendored
Normal file
5
jps-plugin/testData/incremental/pureKotlin/publicPropertyWithPrivateSetter/prop2.kt.new
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun dummy() {
|
||||
if (true) 2 else property
|
||||
}
|
||||
@@ -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
|
||||
------------------------------------------
|
||||
@@ -0,0 +1,6 @@
|
||||
@file:JvmName("TTest")
|
||||
@file:JvmMultifileClass
|
||||
package test
|
||||
|
||||
var property = 1
|
||||
private set
|
||||
@@ -0,0 +1,6 @@
|
||||
package test2
|
||||
import test.*
|
||||
|
||||
fun dummy() {
|
||||
if (true) 1 else property
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
fun dummy() {
|
||||
if (true) 2 else property
|
||||
}
|
||||
Reference in New Issue
Block a user