From 279ee7af86f3d9f05d0eac901c539530095f90bf Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 31 Oct 2025 17:06:26 +0100 Subject: [PATCH] incremental compilation: handle property mutability changes (KT-76927) (cherry picked from commit 43c22d037a7d895066f2e0d9aa32cf13cc0d7543) GitOrigin-RevId: 472c56cf5750b3ccf1950b58d9981dfda7554ab3 --- .../jps/dependency/java/KotlinMeta.java | 6 ++++- .../KotlinJvmDifferentiateStrategy.java | 15 +++++++++++-- .../valPropertyBecameWritable/app.kt | 6 +++++ .../valPropertyBecameWritable/build.log | 22 +++++++++++++++++++ .../valPropertyBecameWritable/foo.kt | 3 +++ .../valPropertyBecameWritable/foo.kt.new | 3 +++ .../IncrementalK2JvmJpsTestGenerated.java | 5 +++++ 7 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/app.kt create mode 100644 plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/build.log create mode 100644 plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/foo.kt create mode 100644 plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/foo.kt.new diff --git a/build/jvm-rules/dependency-graph/src/org/jetbrains/jps/dependency/java/KotlinMeta.java b/build/jvm-rules/dependency-graph/src/org/jetbrains/jps/dependency/java/KotlinMeta.java index 40b19dd14f01..7fe8796925cd 100644 --- a/build/jvm-rules/dependency-graph/src/org/jetbrains/jps/dependency/java/KotlinMeta.java +++ b/build/jvm-rules/dependency-graph/src/org/jetbrains/jps/dependency/java/KotlinMeta.java @@ -477,7 +477,7 @@ public final class KotlinMeta implements JvmMetadata propChange : metaDiff.properties().changed()) { KmProperty changedProp = propChange.getPast(); KotlinMeta.KmPropertiesDiff propDiff = propChange.getDiff(); - if (propDiff.accessRestricted() || propDiff.customAccessorAdded()) { - debug(context, "A property has become less accessible or got custom accessors; affecting its lookup usages ", changedProp.getName()); + + String affectLookupUsagesReason = null; + if (propDiff.accessRestricted()) { + affectLookupUsagesReason = "Property has become less accessible; affecting its lookup usages "; + } + else if (propDiff.customAccessorAdded()) { + affectLookupUsagesReason = "Custom accessors were added to a property; affecting its lookup usages "; + } + else if (propDiff.mutabilityChanged()) { + affectLookupUsagesReason = "Property mutability has changed (val <=> var); affecting its lookup usages "; + } + if (affectLookupUsagesReason != null) { + debug(context, affectLookupUsagesReason, changedProp.getName()); affectMemberLookupUsages(context, changedClass, changedProp.getName(), future, cache); } diff --git a/plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/app.kt b/plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/app.kt new file mode 100644 index 000000000000..4142bd0c0ffc --- /dev/null +++ b/plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/app.kt @@ -0,0 +1,6 @@ +internal fun doSmth(bar: Int) {} + +fun main() { + val foo = Foo() + if (foo.bar != null) doSmth(foo.bar) +} \ No newline at end of file diff --git a/plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/build.log b/plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/build.log new file mode 100644 index 000000000000..1b8a5c96ec39 --- /dev/null +++ b/plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/build.log @@ -0,0 +1,22 @@ +================ Step #1 ================= + +Cleaning output files: + out/production/module/Foo.class + out/production/module/META-INF/module.kotlin_module +End of files +Compiling files: + src/foo.kt +End of files +Exit code: OK +------------------------------------------ +Cleaning output files: + out/production/module/AppKt.class + out/production/module/META-INF/module.kotlin_module +End of files +Compiling files: + src/app.kt +End of files +Exit code: ABORT +------------------------------------------ +COMPILATION FAILED +Smart cast to 'Int' is impossible, because 'bar' is a mutable property that could be mutated concurrently. \ No newline at end of file diff --git a/plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/foo.kt b/plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/foo.kt new file mode 100644 index 000000000000..45e98eff79e6 --- /dev/null +++ b/plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/foo.kt @@ -0,0 +1,3 @@ +class Foo( + val bar: Int? = null +) \ No newline at end of file diff --git a/plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/foo.kt.new b/plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/foo.kt.new new file mode 100644 index 000000000000..5b63b1c7a001 --- /dev/null +++ b/plugins/kotlin/jps/graphImplementationTests/testData/incremental/pureKotlin/valPropertyBecameWritable/foo.kt.new @@ -0,0 +1,3 @@ +class Foo( + var bar: Int? = null +) \ No newline at end of file diff --git a/plugins/kotlin/jps/graphImplementationTests/tests/org/jetbrains/kotlin/jpsGraph/test/IncrementalK2JvmJpsTestGenerated.java b/plugins/kotlin/jps/graphImplementationTests/tests/org/jetbrains/kotlin/jpsGraph/test/IncrementalK2JvmJpsTestGenerated.java index bd1f6dc8b2e9..149c26f0b6d2 100644 --- a/plugins/kotlin/jps/graphImplementationTests/tests/org/jetbrains/kotlin/jpsGraph/test/IncrementalK2JvmJpsTestGenerated.java +++ b/plugins/kotlin/jps/graphImplementationTests/tests/org/jetbrains/kotlin/jpsGraph/test/IncrementalK2JvmJpsTestGenerated.java @@ -601,6 +601,11 @@ public class IncrementalK2JvmJpsTestGenerated extends AbstractIncrementalK2JvmJp runTest("pureKotlin/propertyRedeclaration/"); } + @TestMetadata("valPropertyBecameWritable") + public void testValPropertyBecameWritable() throws Exception { + runTest("pureKotlin/valPropertyBecameWritable/"); + } + @TestMetadata("publicPropertyWithPrivateSetter") public void testPublicPropertyWithPrivateSetter() throws Exception { runTest("pureKotlin/publicPropertyWithPrivateSetter/");