made last changes KMP compliant

This commit is contained in:
Sergey Chernov 2026-03-31 23:00:38 +03:00
parent 311cf6ee44
commit c140567e0c
2 changed files with 33 additions and 17 deletions

View File

@ -436,6 +436,12 @@ class Compiler(
}
}
private fun rememberModuleReferencePos(name: String, pos: Pos) {
if (!moduleReferencePosByName.containsKey(name)) {
moduleReferencePosByName[name] = pos
}
}
private fun predeclareClassMembers(target: MutableSet<String>, overrides: MutableMap<String, Boolean>) {
val saved = cc.savePos()
var depth = 0
@ -948,7 +954,7 @@ class Compiler(
}
}
captureLocalRef(name, slotLoc, pos)?.let { ref ->
moduleReferencePosByName.putIfAbsent(name, pos)
rememberModuleReferencePos(name, pos)
resolutionSink?.reference(name, pos)
return ref
}
@ -1042,7 +1048,7 @@ class Compiler(
moduleEntry.isDelegated
)
captureLocalRef(name, moduleLoc, pos)?.let { ref ->
moduleReferencePosByName.putIfAbsent(name, pos)
rememberModuleReferencePos(name, pos)
resolutionSink?.reference(name, pos)
return ref
}
@ -1069,7 +1075,7 @@ class Compiler(
strictSlotRefs
)
}
moduleReferencePosByName.putIfAbsent(name, pos)
rememberModuleReferencePos(name, pos)
resolutionSink?.reference(name, pos)
return ref
}
@ -1104,7 +1110,7 @@ class Compiler(
val slot = lookupSlotLocation(name)
if (slot != null) {
captureLocalRef(name, slot, pos)?.let { ref ->
moduleReferencePosByName.putIfAbsent(name, pos)
rememberModuleReferencePos(name, pos)
resolutionSink?.reference(name, pos)
return ref
}
@ -1131,7 +1137,7 @@ class Compiler(
strictSlotRefs
)
}
moduleReferencePosByName.putIfAbsent(name, pos)
rememberModuleReferencePos(name, pos)
resolutionSink?.reference(name, pos)
return ref
}

View File

@ -7664,7 +7664,9 @@ class BytecodeCompiler(
private fun noteScopeSlotRef(slot: Int, pos: Pos) {
if (slot >= scopeSlotCount) return
val key = scopeKeyByIndex.getOrNull(slot) ?: return
scopeSlotRefPosByKey.putIfAbsent(key, pos)
if (!scopeSlotRefPosByKey.containsKey(key)) {
scopeSlotRefPosByKey[key] = pos
}
}
private fun resolveSlot(ref: LocalSlotRef): Int? {
@ -7675,11 +7677,15 @@ class BytecodeCompiler(
val localIndex = localSlotIndexByKey[key]
if (localIndex != null) return scopeSlotCount + localIndex
scopeSlotMap[key]?.let {
scopeSlotRefPosByKey.putIfAbsent(key, ref.pos())
if (!scopeSlotRefPosByKey.containsKey(key)) {
scopeSlotRefPosByKey[key] = ref.pos()
}
return it
}
scopeSlotIndexByName[ref.name]?.let {
scopeSlotRefPosByKey.putIfAbsent(key, ref.pos())
if (!scopeSlotRefPosByKey.containsKey(key)) {
scopeSlotRefPosByKey[key] = ref.pos()
}
return it
}
}
@ -7693,7 +7699,9 @@ class BytecodeCompiler(
}
val resolved = scopeSlotMap[scopeKey]
if (resolved != null) {
scopeSlotRefPosByKey.putIfAbsent(scopeKey, ref.pos())
if (!scopeSlotRefPosByKey.containsKey(scopeKey)) {
scopeSlotRefPosByKey[scopeKey] = ref.pos()
}
}
return resolved
}
@ -7708,7 +7716,9 @@ class BytecodeCompiler(
val scopeKey = ScopeSlotKey(refScopeId(ref), refSlot(ref))
val resolved = scopeSlotMap[scopeKey]
if (resolved != null) {
scopeSlotRefPosByKey.putIfAbsent(scopeKey, ref.pos())
if (!scopeSlotRefPosByKey.containsKey(scopeKey)) {
scopeSlotRefPosByKey[scopeKey] = ref.pos()
}
}
return resolved
}