Prevent cross-script module slot aliasing

This commit is contained in:
sergeych committed 2026-04-21 17:34:00 +03:00
1 parent ee634c8dff
commit c80900c503
3 files changed
+58 -9

No files matched your search

@@ -108,11 +108,7 @@ class Script(
seedImportBindings(scope, seedScope)
}
if (moduleSlotPlan.isNotEmpty()) {
scope.applySlotPlan(moduleSlotPlan)
for (name in moduleSlotPlan.keys) {
val record = scope.objects[name] ?: scope.localBindings[name] ?: continue
scope.updateSlotFor(name, record)
}
installModuleSlotPlan(scope)
}
}
@@ -120,12 +116,26 @@ class Script(
if (importBindings.isEmpty() && importedModules.isEmpty()) return
seedImportBindings(scope, seedScope)
if (moduleSlotPlan.isNotEmpty()) {
scope.applySlotPlan(moduleSlotPlan)
for (name in moduleSlotPlan.keys) {
val record = scope.objects[name] ?: scope.localBindings[name] ?: continue
scope.updateSlotFor(name, record)
installModuleSlotPlan(scope)
}
}
private fun installModuleSlotPlan(scope: Scope) {
for ((name, index) in moduleSlotPlan) {
if (scope.getSlotIndexOf(name) != null) continue
if (scope.hasSlotPlanConflict(mapOf(name to index))) {
val record = scope.objects[name]
?: scope.localBindings[name]
?: ObjRecord(ObjUnset, isMutable = true)
scope.allocateSlotFor(name, record)
} else {
scope.applySlotPlan(mapOf(name to index))
}
}
for (name in moduleSlotPlan.keys) {
val record = scope.objects[name] ?: scope.localBindings[name] ?: continue
scope.updateSlotFor(name, record)
}
}
private suspend fun seedModuleLocals(
@@ -5654,6 +5654,14 @@ class CmdFrame(
if (index < target.slotCount) return index
return index
}
if (target.hasSlotPlanConflict(mapOf(name to index))) {
val record = target.getLocalRecordDirect(name)
?: target.localBindings[name]
?: target.parent?.get(name)
?: target.get(name)
?: ObjRecord(ObjUnset, isMutable = true)
return target.allocateSlotFor(name, record)
}
target.applySlotPlan(mapOf(name to index))
val existing = target.getLocalRecordDirect(name) ?: target.localBindings[name]
if (existing != null) {