Improve variable resolution and expand test coverage; improved wahtsnew

This commit is contained in:
sergeych committed 2026-02-17 08:06:06 +03:00
1 parent afa4b20070
commit b6851b7098
4 files changed
+134 -22

No files matched your search

@@ -7113,9 +7113,30 @@ class BytecodeCompiler(
private fun resolveReceiverClassForScopeCollection(ref: ObjRef): ObjClass? {
return when (ref) {
is LocalSlotRef -> nameObjClass[ref.name] ?: resolveTypeNameClass(ref.name)
is LocalVarRef -> nameObjClass[ref.name] ?: resolveTypeNameClass(ref.name)
is FastLocalVarRef -> nameObjClass[ref.name] ?: resolveTypeNameClass(ref.name)
is LocalSlotRef -> {
val ownerScopeId = ref.captureOwnerScopeId ?: ref.scopeId
val ownerSlot = ref.captureOwnerSlot ?: ref.slot
slotTypeByScopeId[ownerScopeId]?.get(ownerSlot)
?: slotInitClassByKey[ScopeSlotKey(ownerScopeId, ownerSlot)]
?: nameObjClass[ref.name]
?: resolveTypeNameClass(ref.name)
}
is LocalVarRef -> {
val key = localSlotInfoMap.entries.firstOrNull { it.value.name == ref.name }?.key
key?.let {
slotTypeByScopeId[it.scopeId]?.get(it.slot)
?: slotInitClassByKey[it]
} ?: nameObjClass[ref.name]
?: resolveTypeNameClass(ref.name)
}
is FastLocalVarRef -> {
val key = localSlotInfoMap.entries.firstOrNull { it.value.name == ref.name }?.key
key?.let {
slotTypeByScopeId[it.scopeId]?.get(it.slot)
?: slotInitClassByKey[it]
} ?: nameObjClass[ref.name]
?: resolveTypeNameClass(ref.name)
}
is BoundLocalVarRef -> slotObjClass[ref.slotIndex()]
is QualifiedThisRef -> resolveTypeNameClass(ref.typeName)
is ListLiteralRef -> ObjList.type
@@ -1,3 +1,20 @@
/*
* Copyright 2026 Sergey S. Chernov real.sergeych@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* Ensure stdlib Obj*-defined docs (like String methods added via ObjString.addFnDoc)
* are initialized before registry lookups for completion/quick docs.
@@ -33,6 +50,19 @@ object StdlibDocsBootstrap {
val _range = net.sergeych.lyng.obj.ObjRange.type
@Suppress("UNUSED_VARIABLE")
val _buffer = net.sergeych.lyng.obj.ObjBuffer.type
// Also touch time module types so their docs (moduleName = "lyng.time") are registered
// This enables completion/quick docs for symbols imported via `import lyng.time` (e.g., Instant, DateTime, Duration)
try {
@Suppress("UNUSED_VARIABLE")
val _instant = net.sergeych.lyng.obj.ObjInstant.type
@Suppress("UNUSED_VARIABLE")
val _datetime = net.sergeych.lyng.obj.ObjDateTime.type
@Suppress("UNUSED_VARIABLE")
val _duration = net.sergeych.lyng.obj.ObjDuration.type
} catch (_: Throwable) {
// Optional; absence should not affect stdlib core
}
} catch (_: Throwable) {
// Best-effort; absence should not break consumers
} finally {
+25 -11
View File
@@ -132,15 +132,29 @@ class StdlibTest {
""".trimIndent())
}
// @Test
// fun testFunFromSample() = runTest {
// range should be iterable if it is intrange
// eval("""
// val data = 1..5 // or [1, 2, 3, 4, 5]
// fun test() {
// data.filter { it % 2 == 0 }.map { it * it }
// }
// test()
// """.trimIndent())
// }
@Test
fun testFilter1() = runTest {
// range should be iterable if it is intrange
eval("""
val data = 1..5 // or [1, 2, 3, 4, 5]
assert( data is Iterable<Int> )
fun test() {
data.filter { it % 2 == 0 }.map { it * it }
}
test()
""".trimIndent())
}
@Test
fun testFilter2() = runTest {
eval("""
val data = [1, 2, 3, 4, 5]
assert( data is Iterable<Int> )
fun test() {
data.filter { it % 2 == 0 }.map { it * it }
}
test()
"""
)
}
}