yet another import fix

This commit is contained in:
Sergey Chernov 2026-04-13 22:48:52 +03:00
parent 3b6bdda0a4
commit e925195495
3 changed files with 34 additions and 3 deletions

1
.gitignore vendored
View File

@ -28,3 +28,4 @@ debug.log
/compile_metadata_output.txt
test_output*.txt
/site/src/version-template/lyng-version.js
/bugs/

View File

@ -146,18 +146,27 @@ class CliLocalModuleImportRegressionJvmTest {
val headers = Map<String, String>()
fn startListen(port, host) {
var eager = Bravo()
eager.doSomething()
tcpServer = Net.tcpListen(port, host)
// println("tcpServer.isOpen: " + tcpServer.isOpen()) // historical workaround; should not be needed
println("tcpServer.isOpen: " + tcpServer.isOpen())
launch {
try {
while (true) {
println("wait for accept...")
val tcpSocket = tcpServer.accept()
println("var bravo = Bravo()")
var bravo = Bravo()
println("bravo.doSomething()...")
bravo.doSomething()
println("bravo.doSomething()... OK")
tcpSocket.close()
break
}
} catch (e) {
println("ERR [Alpha.startListen]: '", e, "'")
} finally {
println("FIN [Alpha.startListen]")
tcpServer.close()
}
}
@ -259,6 +268,7 @@ class CliLocalModuleImportRegressionJvmTest {
delay(50)
val socket = Net.tcpConnect("127.0.0.1", $port)
println("send ping...")
socket.writeUtf8("ping")
socket.flush()
socket.close()
@ -269,8 +279,10 @@ class CliLocalModuleImportRegressionJvmTest {
val result = runCli(mainFile.toString())
assertTrue(result.err.isBlank(), result.err)
assertFalse(result.out.contains("ERR [Alpha.startListen]"), result.out)
assertFalse(result.out.contains("module capture 'Bravo'"), result.out)
assertTrue(result.out.contains("Bravo.doSomething"), result.out)
assertTrue(result.out.contains("bravo.doSomething()... OK"), result.out)
assertEquals(2, Regex("Bravo\\.doSomething").findAll(result.out).count(), result.out)
} finally {
root.toFile().deleteRecursively()
}

View File

@ -2086,7 +2086,7 @@ class Compiler(
return null
}
if (scopeSeedNames.contains(name)) {
val isModuleSlot = modulePlan != null && slotLoc.scopeId == modulePlan.id
val isModuleSlot = resolvesToModuleSeedSlot(name, slotLoc)
if (!isModuleSlot || useScopeSlots) return null
}
recordCaptureSlot(name, slotLoc)
@ -2105,6 +2105,24 @@ class Compiler(
)
}
private fun resolvesToModuleSeedSlot(name: String, slotLoc: SlotLocation): Boolean {
val modulePlan = moduleSlotPlan() ?: return false
var current: SlotLocation? = slotLoc
val visitedScopeIds = HashSet<Int>()
while (current != null && visitedScopeIds.add(current.scopeId)) {
if (current.scopeId == modulePlan.id) {
return true
}
val owner = capturePlanStack
.firstOrNull { it.slotPlan.id == current.scopeId }
?.captureOwners
?.get(name)
?: return false
current = owner
}
return false
}
private fun captureSlotRef(name: String, pos: Pos): ObjRef? {
if (capturePlanStack.isEmpty()) return null
if (name == "this") return null