Fix argument priority handling in ObjInstance resolution logic and add corresponding tests
This commit is contained in:
1 parent
7ab439d949
commit
827df9c8cd
3 files changed
+58
-3
No files matched your search
@@ -347,7 +347,16 @@ open class Scope(
|
||||
// 1. Prefer direct locals/bindings declared in this frame
|
||||
tryGetLocalRecord(this, name, currentClassCtx)?.let { return it }
|
||||
|
||||
// 2. Then, check members of thisObj
|
||||
val p = parent
|
||||
|
||||
// 2. If we share thisObj with parent, delegate to parent to maintain
|
||||
// "locals shadow members" priority across the this-context.
|
||||
if (p != null && p.thisObj === thisObj) {
|
||||
return p.get(name)
|
||||
}
|
||||
|
||||
// 3. Otherwise, we are the "primary" scope for this thisObj (or have no parent),
|
||||
// so check members of thisObj before walking up to a different this-context.
|
||||
val receiver = thisObj
|
||||
val effectiveClass = receiver as? ObjClass ?: receiver.objClass
|
||||
for (cls in effectiveClass.mro) {
|
||||
@@ -365,8 +374,8 @@ open class Scope(
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Finally, walk up ancestry
|
||||
return parent?.get(name)
|
||||
// 4. Finally, walk up ancestry to a scope with a different thisObj context
|
||||
return p?.get(name)
|
||||
}
|
||||
|
||||
// Slot fast-path API
|
||||
|
||||
@@ -76,6 +76,7 @@ class ObjInstance(override val objClass: ObjClass) : Obj() {
|
||||
}
|
||||
|
||||
override suspend fun resolveRecord(scope: Scope, obj: ObjRecord, name: String, decl: ObjClass?): ObjRecord {
|
||||
if (obj.type.isArgument) return super.resolveRecord(scope, obj, name, decl)
|
||||
if (obj.type == ObjRecord.Type.Delegated) {
|
||||
val d = decl ?: obj.declaringClass
|
||||
val storageName = "${d?.className}::$name"
|
||||
|
||||
Reference in new issue
Block a user