Recompile files which import companion constant
#KT-44741 Fixed
This commit is contained in:
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMapping
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
@@ -399,7 +400,9 @@ open class IncrementalJvmCache(
|
||||
}
|
||||
|
||||
for (const in oldMap.keys + newMap.keys) {
|
||||
changesCollector.collectMemberIfValueWasChanged(kotlinClass.scopeFqName(), const, oldMap[const], newMap[const])
|
||||
//Constant can be declared via companion object or via const field declaration
|
||||
changesCollector.collectMemberIfValueWasChanged(kotlinClass.scopeFqName(companion = true), const, oldMap[const], newMap[const])
|
||||
changesCollector.collectMemberIfValueWasChanged(kotlinClass.scopeFqName(companion = false), const, oldMap[const], newMap[const])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,11 +602,12 @@ sealed class ChangeInfo(val fqName: FqName) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun LocalFileKotlinClass.scopeFqName() =
|
||||
when (classHeader.kind) {
|
||||
KotlinClassHeader.Kind.CLASS -> className.fqNameForClassNameWithoutDollars
|
||||
else -> className.packageFqName
|
||||
private fun LocalFileKotlinClass.scopeFqName(companion: Boolean = false) = when (classHeader.kind) {
|
||||
KotlinClassHeader.Kind.CLASS -> {
|
||||
className.fqNameForClassNameWithoutDollars.let { if (companion) it.child(DEFAULT_NAME_FOR_COMPANION_OBJECT) else it }
|
||||
}
|
||||
else -> className.packageFqName
|
||||
}
|
||||
|
||||
fun ByteArray.md5(): Long {
|
||||
val d = MessageDigest.getInstance("MD5").digest(this)!!
|
||||
|
||||
+5
@@ -28,6 +28,11 @@ public class IncrementalJvmCompilerRunnerTestGenerated extends AbstractIncrement
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("companionConstantChanged")
|
||||
public void testCompanionConstantChanges() throws Exception {
|
||||
runTest("jps-plugin/testData/incremental/pureKotlin/companionConstantChanged/");
|
||||
}
|
||||
|
||||
@TestMetadata("accessingFunctionsViaPackagePart")
|
||||
public void testAccessingFunctionsViaPackagePart() throws Exception {
|
||||
runTest("jps-plugin/testData/incremental/pureKotlin/accessingFunctionsViaPackagePart/");
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
const val CONSTANT_VALUE = 16
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
const val CONSTANT_VALUE = 17
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
import test.A.Companion.CONSTANT_VALUE
|
||||
|
||||
class B {
|
||||
companion object {
|
||||
fun main() {
|
||||
println("Import companion constant: ${CONSTANT_VALUE}")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
import test.A
|
||||
|
||||
class C {
|
||||
companion object {
|
||||
fun main() {
|
||||
println("Companion constant: ${A.CONSTANT_VALUE}")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package foo
|
||||
|
||||
class DoNotUseConstant {
|
||||
companion object {
|
||||
const val CONSTANT_VALUE = 10
|
||||
fun main() {
|
||||
println("Use local constant: ${CONSTANT_VALUE}")
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
================ Step #1 =================
|
||||
|
||||
Compiling files:
|
||||
src/A.kt
|
||||
src/B.kt
|
||||
src/C.kt
|
||||
src/companionUsage.kt
|
||||
src/constantUsage.kt
|
||||
End of files
|
||||
Exit code: OK
|
||||
------------------------------------------
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package foo
|
||||
|
||||
import test.A
|
||||
|
||||
fun callCompanionConstant() = "Companion constant: ${A.CONSTANT_VALUE}"
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package foo
|
||||
|
||||
import test.A.Companion.CONSTANT_VALUE
|
||||
|
||||
fun importCompanionConstant() = "Import companion constant: ${CONSTANT_VALUE}"
|
||||
|
||||
Reference in New Issue
Block a user