From ed820d6b57f1685ea2563d62c93691a62773f1bd Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Thu, 7 Dec 2023 18:02:25 +0100 Subject: [PATCH] K2 IC: fix lookup recording for a "red" companion object #KT-63665 fixed --- .../kotlin/fir/FirLookupTrackerComponent.kt | 9 ++++-- ...rementalK2JvmCompilerRunnerTestCustom.java | 31 +++++++++++++++++++ .../custom/companionWithSyntaxError/build.log | 23 ++++++++++++++ .../custom/companionWithSyntaxError/main.kt | 7 +++++ .../companionWithSyntaxError/main.kt.new.1 | 8 +++++ .../companionWithSyntaxError/main.kt.new.2 | 7 +++++ 6 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK2JvmCompilerRunnerTestCustom.java create mode 100644 jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/build.log create mode 100644 jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/main.kt create mode 100644 jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/main.kt.new.1 create mode 100644 jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/main.kt.new.2 diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/FirLookupTrackerComponent.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/FirLookupTrackerComponent.kt index ddab7bf878d..295de8396f3 100644 --- a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/FirLookupTrackerComponent.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/FirLookupTrackerComponent.kt @@ -19,10 +19,13 @@ abstract class FirLookupTrackerComponent : FirSessionComponent { } fun FirLookupTrackerComponent.recordCallLookup(callInfo: AbstractCallInfo, inType: ConeKotlinType) { - if (inType.classId?.isLocal == true) return + val classId = inType.classId + if (classId?.isLocal == true) return val scopes = SmartList(inType.renderForDebugging().replace('/', '.')) - if (inType.classId?.shortClassName?.asString() == "Companion") { - scopes.add(inType.classId!!.outerClassId!!.asString().replace('/', '.')) + if (classId != null && classId.shortClassName.asString() == "Companion") { + classId.outerClassId?.asString()?.replace('/', '.')?.let { + scopes.add(it) + } } recordLookup(callInfo.name, scopes, callInfo.callSite.source, callInfo.containingFile.source) } diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK2JvmCompilerRunnerTestCustom.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK2JvmCompilerRunnerTestCustom.java new file mode 100644 index 00000000000..5c5fea84b26 --- /dev/null +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalK2JvmCompilerRunnerTestCustom.java @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.incremental; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TargetBackend; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +@SuppressWarnings("all") +@RunWith(JUnit3RunnerWithInners.class) +public class IncrementalK2JvmCompilerRunnerTestCustom extends AbstractIncrementalK2JvmCompilerRunnerTest { + @TestMetadata("jps/jps-plugin/testData/incremental/custom") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Custom extends AbstractIncrementalK2JvmCompilerRunnerTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + @TestMetadata("companionWithSyntaxError") + public void testCompanionWithSyntaxError() throws Exception { + runTest("jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/"); + } + } +} diff --git a/jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/build.log b/jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/build.log new file mode 100644 index 00000000000..3e31dd81fb5 --- /dev/null +++ b/jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/build.log @@ -0,0 +1,23 @@ +================ Step #1 ================= + +After chunkBuildStarted. Marked as dirty by Kotlin: + src/main.kt +Cleaning output files: + out/production/module/A$Companion.class + out/production/module/A.class + out/production/module/META-INF/module.kotlin_module +End of files +Compiling files: + src/main.kt +End of files +Exit code: ABORT +------------------------------------------ +COMPILATION FAILED + +================ Step #2 ================= + +Compiling files: + src/main.kt +End of files +Exit code: OK +------------------------------------------ \ No newline at end of file diff --git a/jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/main.kt b/jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/main.kt new file mode 100644 index 00000000000..090b880c4fc --- /dev/null +++ b/jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/main.kt @@ -0,0 +1,7 @@ +class A() { + + companion object { + fun equals(): Boolean = + TODO() + } +} \ No newline at end of file diff --git a/jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/main.kt.new.1 b/jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/main.kt.new.1 new file mode 100644 index 00000000000..2cf0e5db176 --- /dev/null +++ b/jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/main.kt.new.1 @@ -0,0 +1,8 @@ +class A() { +} // extra curly brace + + companion object { + fun equals(): Boolean = + TODO() + } +} \ No newline at end of file diff --git a/jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/main.kt.new.2 b/jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/main.kt.new.2 new file mode 100644 index 00000000000..090b880c4fc --- /dev/null +++ b/jps/jps-plugin/testData/incremental/custom/companionWithSyntaxError/main.kt.new.2 @@ -0,0 +1,7 @@ +class A() { + + companion object { + fun equals(): Boolean = + TODO() + } +} \ No newline at end of file