Fix duplicate stdlib import redefinition
This commit is contained in:
parent
a1ea09440d
commit
6171b0d95f
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -94,7 +94,11 @@ class ModuleScope(
|
|||||||
if (newName != null) {
|
if (newName != null) {
|
||||||
val existing = scope.objects[newName]
|
val existing = scope.objects[newName]
|
||||||
if (existing != null) {
|
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")
|
scope.raiseError("symbol ${existing.importedFrom?.packageName}.$newName already exists, redefinition on import is not allowed")
|
||||||
// already imported
|
// already imported
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user