diff --git a/lyng/src/jvmTest/kotlin/net/sergeych/CliLocalModuleImportRegressionJvmTest.kt b/lyng/src/jvmTest/kotlin/net/sergeych/CliLocalModuleImportRegressionJvmTest.kt new file mode 100644 index 0000000..c2a2509 --- /dev/null +++ b/lyng/src/jvmTest/kotlin/net/sergeych/CliLocalModuleImportRegressionJvmTest.kt @@ -0,0 +1,44 @@ +package net.sergeych + +import kotlinx.coroutines.runBlocking +import java.nio.file.Files +import kotlin.io.path.writeText +import kotlin.test.Test + +class CliLocalModuleImportRegressionJvmTest { + + @Test + fun localModuleUsingLaunchAndNetImportsWithoutStdlibRedefinition() = runBlocking { + val root = Files.createTempDirectory("lyng-cli-import-regression") + try { + val packageDir = Files.createDirectories(root.resolve("package1")) + val mainFile = root.resolve("main.lyng") + val alphaFile = packageDir.resolve("alpha.lyng") + + mainFile.writeText( + """ + import package1.alpha + + println("ok") + """.trimIndent() + ) + alphaFile.writeText( + """ + import lyng.io.net + + class Alpha { + fn startListen(port, host) { + launch { + println(port, host) + } + } + } + """.trimIndent() + ) + + executeFile(mainFile.toString(), emptyList()) + } finally { + root.toFile().deleteRecursively() + } + } +} diff --git a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/ModuleScope.kt b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/ModuleScope.kt index e166985..1eae982 100644 --- a/lynglib/src/commonMain/kotlin/net/sergeych/lyng/ModuleScope.kt +++ b/lynglib/src/commonMain/kotlin/net/sergeych/lyng/ModuleScope.kt @@ -94,7 +94,11 @@ class ModuleScope( if (newName != null) { val existing = scope.objects[newName] if (existing != null) { - if (existing.importedFrom != record.importedFrom) + val sameBinding = + existing === record || + existing.importedFrom == record.importedFrom || + existing.value === record.value + if (!sameBinding) scope.raiseError("symbol ${existing.importedFrom?.packageName}.$newName already exists, redefinition on import is not allowed") // already imported } else {