From df35e5431c461870c6eeb17993d0364d2792854f Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Wed, 12 Apr 2023 14:51:24 +0200 Subject: [PATCH] FIR: fix libs filtering for abs/rel paths combinations Some of the incoming paths "absoluteness" may not match the one of the corresponding library path, and that leaded to incorrect filtering out some items in the deserialized symbol providers. Fix the filtering to account for the mismatch. #KT-57535 fixed --- .../AbstractFirDeserializedSymbolProvider.kt | 10 +++++++++- .../jetbrains/kotlin/cli/LauncherScriptTest.kt | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/AbstractFirDeserializedSymbolProvider.kt b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/AbstractFirDeserializedSymbolProvider.kt index 712e7dba351..f1aae62e290 100644 --- a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/AbstractFirDeserializedSymbolProvider.kt +++ b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/AbstractFirDeserializedSymbolProvider.kt @@ -57,7 +57,15 @@ abstract class LibraryPathFilter { override fun accepts(path: Path?): Boolean { if (path == null) return false - return libs.any { path.startsWith(it) } + val isPathAbsolute = path.isAbsolute + val absolutePath by lazy(LazyThreadSafetyMode.NONE) { path.toAbsolutePath() } + return libs.any { + when { + it.isAbsolute && !isPathAbsolute -> absolutePath.startsWith(it) + !it.isAbsolute && isPathAbsolute -> path.startsWith(it.toAbsolutePath()) + else -> path.startsWith(it) + } + } } } } diff --git a/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt b/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt index 718999acbde..8800ebfe27f 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt @@ -21,6 +21,7 @@ import com.intellij.openapi.util.text.StringUtil import org.jetbrains.kotlin.cli.common.CompilerSystemProperties import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler +import org.jetbrains.kotlin.test.CompilerTestUtil import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.TestCaseWithTmpdir import org.jetbrains.kotlin.test.util.KtTestUtil @@ -507,4 +508,21 @@ println(42) expectedStderr = "" ) } + + fun testK2ClassPathWithRelativeDir() { + val file1kt = tmpdir.resolve("file1.kt").apply { + writeText("class C") + } + CompilerTestUtil.executeCompilerAssertSuccessful(K2JVMCompiler(), listOf("-d", tmpdir.absolutePath, "-language-version", "2.0", file1kt.absolutePath)) + val file2kt = tmpdir.resolve("file1.kt").apply { + writeText("val c = C()") + } + runProcess( + "kotlinc", + "-cp", ".", "-d", ".", "-language-version", "2.0", file2kt.absolutePath, + workDirectory = tmpdir, + expectedStdout = "", + expectedStderr = "warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features\n" + ) + } }